NetBSD-Bugs archive

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

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



The following reply was made to PR bin/57438; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/57438: set -o with unknown option aborts a script
Date: Sat, 27 May 2023 12:30:32 +0700

 Alternatively (the previous form is the common idiom
 for this kind of thing) in this case you could also
 just do
 
 	command set -o pipefail 2>/dev/null
 
 and you can test the exit status if you need to know whether
 it worked.
 
 In addition to supressing function execution, and requiring
 a utility instead, "command" also reduces the status of a
 special built-in to just being a regular one, and those (like
 any other utility) do not cause shell exit on error (unless -e
 is enabled, but please be VERY certain you know what you are
 doing before using that option, even experts get fooled by how
 that works - or doesn't).
 
 But for this particular case, (pipefail) the script exiting
 if the option cannot be set is often desireable.  Scripts that
 need pipefail enabled will usually not work correctly without
 it, and the option should not be enabled for scripts not
 written to expect it, it can cause unanticipated behaviour.
 
 kre
 
 ps: another, cumbersome, method to discover what options
 set -o supports is just to use "set -o", and match against
 the output.
 


Home | Main Index | Thread Index | Old Index