Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Issue trying to save and restore options



Alexandre Rames wrote on Wed, 23 May 2018 08:54 -0700:
> username% OPTS=$(set +o)

The 'set' runs inside a subshell so it sees different options:

[[[
% set +o >1
% printf '%s' "$(set +o)" >2
% diff 1 2 
116c116
< set -o monitor
---
> set +o monitor
177c177
< set -o zle
---
> set +o zle
]]]

(The 'zle' option controls whether the line editor is enabled.)

So, you could try capturing the output of 'set +o' using redirections
rather than command substitutions; that should work and remain shell-
agnostic.  (If you want a shell-specific solutions there are other ways,
e.g., check $ZSH_VERSION and then use ${(kv)options} to save the
values.)

As to whether the behaviour of +o in a subshell should be changed, I'll
leave that for others.



Messages sorted by: Reverse Date, Date, Thread, Author