NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/57438: set -o with unknown option aborts a script



>Number:         57438
>Category:       bin
>Synopsis:       set -o with unknown option aborts a script
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 25 19:30:00 +0000 2023
>Originator:     Valery Ushakov
>Release:        NetBSD 10
>Organization:
>Environment:
uname -a
NetBSD krups 10.99.2 NetBSD 10.99.2 (KRUPS) #0: Wed Dec 28 02:08:31 MSK 2022  uwe@majava:/home/uwe/work/netbsd/cvs/src/sys/arch/sparc/compile/KRUPS sparc

>Description:
If a script uses set -o ... with an unknown option, the script
immediately terminates with exit code of 2.

I suspect the problem is that set builtin reuses the same code
that is used to parse the actual command line options.
When processing the command line, exiting with code 2 is the
appropriate action.  It is not an appropriate action when set
builtin is called inside a script.

>How-To-Repeat:
$ sh -c 'echo hello; set -o foobar; echo world'
hello
set: Unknown option -o foobar
$

Compare

bash -c 'echo hello; set -o foobar; echo world'
hello
bash: line 1: set: foobar: invalid option name
world

>Fix:



Home | Main Index | Thread Index | Old Index