Bug 73500

Summary: 'set +o' in /bin/sh does not include unset options
Product: Base System Reporter: Jilles Tjoelker <jilles>
Component: standardsAssignee: Stefan Farfeleder <stefanf>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 6.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
options.c.diff none

Description Jilles Tjoelker freebsd_committer freebsd_triage 2004-11-03 21:10:33 UTC
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.

Fix: Include unset options with '+o' in the output of 'set +o'.
Patch included.
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.
Comment 1 Peter Pentchev freebsd_committer freebsd_triage 2004-11-04 08:45:37 UTC
Responsible Changed
From-To: freebsd-standards->tjr

Over to Tim J. Robbins, who implemented the current 'set +o' output 
in rev. 1.19 of options.c.
Comment 2 Tim Robbins freebsd_committer freebsd_triage 2004-12-19 04:24:54 UTC
Responsible Changed
From-To: tjr->freebsd-standards

Unassign due to lack of time.
Comment 3 Stefan Farfeleder freebsd_committer freebsd_triage 2005-09-10 11:01:09 UTC
Responsible Changed
From-To: freebsd-standards->stefanf

I'll handle this.
Comment 4 Stefan Farfeleder freebsd_committer freebsd_triage 2005-10-29 19:43:01 UTC
State Changed
From-To: open->patched

Committed in a slightly modified way.  Thanks!
Comment 5 Stefan Farfeleder freebsd_committer freebsd_triage 2005-12-26 18:19:30 UTC
State Changed
From-To: patched->closed

Also fixed in RELENG_{5,6}.