The command 'set -o' shows the current shell options in an unspecified
format. Less well-known is the variant 'set +o', which should output the
current shell options "in a format that is suitable for reinput to the
shell as commands that achieve the same options settings".[*]
That means it should be possible to do
save_options=$(set +o)
then change some options, then later restore the shell options with
eval "$save_options"
On all pdksh variants (as well as zsh), 'set +o' is currently inadequate
for that purpose because it only outputs the currently active shell
options, and not the inactive ones.
Even the old ksh88, which pdksh is a clone of (and on which most of
POSIX is based), acts correctly in this regard.
The simple patch below makes 'set +o' compatible with the POSIX spec.
Thanks,
- M.
[*]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_03
(scroll down to '+o')
Index: misc.c
===================================================================
RCS file: /cvs/src/bin/mksh/misc.c,v
retrieving revision 1.241
diff -u -r1.241 misc.c
--- misc.c 21 Jan 2016 18:25:07 -0000 1.241
+++ misc.c 27 Feb 2016 03:36:04 -0000
@@ -217,8 +217,8 @@
/* short version like AT&T ksh93 */
shf_puts(Tset, shl_stdout);
while (i < NELEM(options)) {
- if (Flag(i) && OFN(i)[0])
- shprintf(" -o %s", OFN(i));
+ if (OFN(i)[0])
+ shprintf(" %co %s", Flag(i) ? '-' : '+', OFN(i));
++i;
}
shf_putc('\n', shl_stdout);