This seems to be a bug. (I'm Cc-ing bug-bash) When you set the 'i' flag as an option to bash, it works:
dualbus@hp ~ % bash -O checkwinsize -ic 'echo "$COLUMNS"' 136 This is because of the special treatment that 'i' gets in shell.c. There are some tests there for the value of 'forced_interactive' (the variable set by -i ), and these call init_interactive() when forced_interactive is true (there are certain variations, but these don't matter much). But, when you set the 'i' flag via the set builtin, no such special treatment is given to that change. It just calls change_flag(flag_name, ...) and it assumes it did its job correctly. dualbus@hp ~ % bash -O checkwinsize -c 'set -i; echo "$COLUMNS"' (empty) So, I see two options: - We call init_interactive() for the 'i' flag in set. - Disallow set [-+]i It's a mess to be able to change the interactive flag like that with set -i/set +i though, and it will probably lead to more bugs. On the other hand, that's not a real reason to disallow it. It's just more work. But, either way, I consider that a bug. Now, this is by no means a complete patch, but, it shows where the bug probably lies: dualbus@hp ~ % ~/local/src/bash/bash -O checkwinsize -c 'set -i; echo "$COLUMNS"' 136 I've attached it.
diff --git a/builtins/set.def b/builtins/set.def index c4a7001..0b22b4a 100644 --- a/builtins/set.def +++ b/builtins/set.def @@ -704,6 +704,12 @@ set_builtin (list) return (EXECUTION_FAILURE); } opts_changed = 1; + if(flag_name == 'i' && on_or_off == '-') + { + init_interactive(); + /*if(check_window_size)*/ + get_new_window_size (0, (int *)0, (int *)0); + } } } else diff --git a/shell.c b/shell.c index 2fd8179..038d27c 100644 --- a/shell.c +++ b/shell.c @@ -320,7 +320,7 @@ static int run_wordexp __P((char *)); static int uidget __P((void)); -static void init_interactive __P((void)); +void init_interactive __P((void)); static void init_noninteractive __P((void)); static void init_interactive_script __P((void)); @@ -1635,7 +1635,7 @@ set_shell_name (argv0) shell_name = PROGRAM; } -static void +void init_interactive () { expand_aliases = interactive_shell = startup_state = 1;