> 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';