Martijn Dekker dixit:
>Martijn Dekker schreef op 27-02-16 om 04:44:
>> That means it should be possible to do
>>
>>         save_options=$(set +o)

No, the rationale says something about dotfiles. so probably:
        set +o >tempfile
        . ./tempfile

>Hmm. "-o interactive" is killing that with an "interactive: bad option"
>error.
[…]
>Ah ha! I see now: the 'interactive' option is turned off in subshells
>(including command substitutions), so the output of

That should work with the construction I gave above.

>This clearly needs more work. Perhaps those two options should simply be
>blacklisted from "set +o" output? Thoughts?

I see two different problems, one is easier to tackle.

Your patch is fine but it doesn’t touch the manpage,
which says set +o shows the long names of all currently
enabled options. (Easy to fix, but a change in the base
language, so I’m holding this off for R53 and won’t add
it to R52c with the accumulating bugfixes.)

Moreover, we have flags that, behind the scenes, are not
0 or 1 but, for example, 2 until someone sets them manually.
ksh93 tackles this rather elegantly:

tg@blau:~ $ ksh93
ksh93:/home/tg $ set -o emacs
ksh93:/home/tg $ set -o >x; rs <x
Current option settings       login_shell              off
allexport                off  markdirs                 off
bgnice                   on   monitor                  on
braceexpand              on   multiline                off
clobber                  on   notify                   off
emacs                    on   pipefail                 off
errexit                  off  privileged               off
exec                     on   rc                       on
glob                     on   restricted               off
globstar                 off  showme                   off
gmacs                    off  trackall                 off
histexpand               off  unset                    on
ignoreeof                off  verbose                  off
interactive              on   vi                       off
keyword                  off  viraw                    on
letoctal                 off  xtrace                   off
log                      on
ksh93:/home/tg $ set +o
set --default --bgnice --braceexpand --emacs --monitor --viraw

While I won’t add --gnu-long-options, ever, this is something
that could achieve the desired effect. (There’s also another
tristate option planned.)

I’ll put the issue on my TODO only, for now, but thanks anyway.

Ah, another thing your patch won’t catch:
        set -o posix; set -o braceexpand; set +o
The output of set +o must have -o braceexpand AFTER -o posix
(and ±o sh) as turning on one of the latter turns off the
former as side effect.

bye,
//mirabilos
-- 
“It is inappropriate to require that a time represented as
 seconds since the Epoch precisely represent the number of
 seconds between the referenced time and the Epoch.”
        -- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2

Reply via email to