Skip site navigation (1)Skip section navigation (2)
Date:      Wed,  3 Nov 2004 22:02:29 +0100 (CET)
From:      Jilles Tjoelker <jilles@stack.nl>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   standards/73500: 'set +o' in /bin/sh does not include unset options
Message-ID:  <20041103210229.19704619F@hammer.stack.nl>
Resent-Message-ID: <200411032110.iA3LAXFv052984@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         73500
>Category:       standards
>Synopsis:       'set +o' in /bin/sh does not include unset options
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 03 21:10:33 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Jilles Tjoelker
>Release:        FreeBSD 6.0-CURRENT amd64
>Organization:
MCGV Stack
>Environment:
System: FreeBSD hammer.stack.nl 6.0-CURRENT FreeBSD 6.0-CURRENT #3: Mon Nov 1 18:36:46 CET 2004 marcolz@hammer.stack.nl:/usr/obj/usr/src/sys/HAMMER amd64


>Description:
The output of 'set +o' only contains options that are set, not options that
are unset.
IEEE Std 1003.1-2001 says:
    +o  Write the current option settings to standard output in a format that
        is suitable for reinput to the shell as commands that achieve the same
        options settings.
Obviously, the current implementation does not achieve that.
The man page says this which might be interpreted both ways:
    If +o is used without an argument, the current option settings are output
    in a format suitable for re-input into the shell.
>How-To-Repeat:
jilles@hammer /home/jilles$ /bin/sh
$ set +o
set -o interactive -o monitor -o stdin
$

A more complicated real-world-like demonstration is the following shell
script:

#!/bin/sh
settings="$(set +o)"
set -o noglob
eval "$settings"
echo /*

It outputs '/*' with the current version of /bin/sh.  The script works
correctly (shows all files directly under /) with bash-2.05b.007_2 and
Solaris 10 /usr/xpg4/bin/sh.
>Fix:
Include unset options with '+o' in the output of 'set +o'.
Patch included.

--- options.c.diff begins here ---
--- src/bin/sh/options.c.orig	Wed Apr  7 10:12:45 2004
+++ src/bin/sh/options.c	Wed Nov  3 18:42:45 2004
@@ -196,7 +196,7 @@
 STATIC void
 minus_o(char *name, int val)
 {
-	int doneset, i;
+	int i;
 
 	if (name == NULL) {
 		if (val) {
@@ -207,16 +207,11 @@
 					optlist[i].val ? "on" : "off");
 		} else {
 			/* Output suitable for re-input to shell. */
-			for (doneset = i = 0; i < NOPTS; i++)
-				if (optlist[i].val) {
-					if (!doneset) {
-						out1str("set");
-						doneset = 1;
-					}
-					out1fmt(" -o %s", optlist[i].name);
-				}
-			if (doneset)
-				out1c('\n');
+			out1str("set");
+			for (i = 0; i < NOPTS; i++)
+				out1fmt(" %co %s", optlist[i].val ? '-' : '+',
+					optlist[i].name);
+			out1c('\n');
 		}
 	} else {
 		for (i = 0; i < NOPTS; i++)
--- options.c.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041103210229.19704619F>