Re: -i option of set missing in man bash
You can avoid these surprises by making -i just as other options, i.e., working within the shell not just when a shell is started. [..] I don't think it's good to have set +/-i available after initialization. It's more complex to handle, and with little (or null?) gain. If you're using set -i inside a script, then you're clearly doing it the wrong way (whatever you're trying to achieve). *But* I do think it's misleading to have bash accept the 'i' flag, but not others. It also leads people to think that setting it from 'set' worked, because it's in $- if it has an 'i' in $-, then it *must* be interactive, right?, wrong. Also, we're already disallowing the rest of the options already: dualbus@hp:~$ bash -c 'for f in c i l r s D; do (set -$f; echo $-); done' bash: line 0: set: -c: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc hiBc bash: line 0: set: -l: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc hrBc bash: line 0: set: -s: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc bash: line 0: set: -D: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc So, why not disallow 'i' also? I propose the attached patch to deal with this (basically, it disallows setting 'i' with 'set'). Patched bash: dualbus@hp:~$ ~/local/src/bash/bash -c 'for f in c i l r s D; do (set -$f; echo $-); done' /home/dualbus/local/src/bash/bash: line 0: set: -c: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc /home/dualbus/local/src/bash/bash: line 0: set: -i: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc /home/dualbus/local/src/bash/bash: line 0: set: -l: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc hrBc /home/dualbus/local/src/bash/bash: line 0: set: -s: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc /home/dualbus/local/src/bash/bash: line 0: set: -D: invalid option set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] hBc -- Eduardo diff --git a/builtins/set.def b/builtins/set.def index c4a7001..4b885cb 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -693,8 +693,11 @@ set_builtin (list) return (r); } } - else if (change_flag (flag_name, on_or_off) == FLAG_ERROR) + else if (flag_name == 'i' || change_flag (flag_name, on_or_off) == FLAG_ERROR) { + /* We disallow changing the 'i' flag from the set builtin, because it +confuses people. Also because setting it here is a no-op, and it just +messes up with the value of $- */ s[0] = on_or_off; s[1] = flag_name; s[2] = '\0';
IFS is ignored when concatenating array elements
This works as I would expect: $ arr=(a b c); IFS=+; echo ${arr[*]/a/x} x+b+c But for some reason, this ignores IFS: $ arr=(a b c); IFS=+; arr=${arr[*]/a/x}; echo $arr x b c Here is the behaviour of other shells that allow that kind of syntax: input: arr=(a b c); IFS=+; echo ${arr[*]/a/x} === bash: x+b+c ksh: x+b+c yash: x+b+c zsh: x+b+c input: arr=(a b c); IFS=+; arr=${arr[*]/a/x}; echo $arr === bash: x b c ksh: x+b+c yash: x+b+c zsh: x+b+c
Re: -i option of set missing in man bash
On Friday, March 13, 2015, Chet Ramey chet.ra...@case.edu wrote: On 3/12/15 2:13 PM, Peng Yu wrote: The -i option obviously works with set. But it is missing in the man page. Should this be added? No. It's really only there for completeness, so things like `set $-' work as expected without error. But if something is in the implementation, it should be also in the documentation, right? There is a level of absurdity about this. I can put a sentence in saying that the -i, -c, and -s options are only effective at invocation and no-ops when used with `set' -- if you've ever wondered how you get an 80-page man `page', that's how -- but would that really have made a difference? It's only there for convenience, after all, and has no effect. You can avoid these surprises by making -i just as other options, i.e., working within the shell not just when a shell is started. The document should be complete. Why it matters you have a 8, 80, or 800 manpages? Few people prints it. After all, most people just search it and it is better to make it complete. I believe the best way to make the manpage short is to make the implementation intuitive so that people can derive the behavior in complex cases based on what are described in simpler cases in the manual. With this in mind, one avoids the description of complexes cases in the manual. -i is described in the OPTIONS section of the man page, since invocation is the only place using it makes sense. Not necessarily. See my other example sent recently on the mailing list of trying to get COLUMNS. With regards to COLUMNS, one doesn't need interactive mode to do that. There are lots of ways to set COLUMNS to the screen width. It's much more productive to state your requirements clearly so people can suggest solutions -- people here are more than happy to help -- than to complain that the shell isn't satisfying your assumptions. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.edu javascript:; http://cnswww.cns.cwru.edu/~chet/ -- Regards, Peng
Re: -i option of set missing in man bash
On 3/12/15 2:13 PM, Peng Yu wrote: The -i option obviously works with set. But it is missing in the man page. Should this be added? No. It's really only there for completeness, so things like `set $-' work as expected without error. But if something is in the implementation, it should be also in the documentation, right? There is a level of absurdity about this. I can put a sentence in saying that the -i, -c, and -s options are only effective at invocation and no-ops when used with `set' -- if you've ever wondered how you get an 80-page man `page', that's how -- but would that really have made a difference? It's only there for convenience, after all, and has no effect. -i is described in the OPTIONS section of the man page, since invocation is the only place using it makes sense. Not necessarily. See my other example sent recently on the mailing list of trying to get COLUMNS. With regards to COLUMNS, one doesn't need interactive mode to do that. There are lots of ways to set COLUMNS to the screen width. It's much more productive to state your requirements clearly so people can suggest solutions -- people here are more than happy to help -- than to complain that the shell isn't satisfying your assumptions. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/