[colug-432] Shell Tests: Beware of leading '-'; Thanks Rob

Rob Stampfli rob944 at cboh.org
Wed Oct 7 14:36:56 EDT 2015


On Tue, Oct 06, 2015 at 06:34:09PM -0400, jep200404 at columbus.rr.com wrote:
> Any comments on the ${var:+value} stuff?
> It is on page 4-7 (The Bourne Shell and Korn Shell chapter)
> of the June 1998 printing of "UNIX In A Nutshell" that has
> 1986 and 1992 copyrights. 

Yes, I think this << [ "${1:+is_set}" != "is_set" ] >> should work,
too, but with one caveat:  I often do a "set -o nounset" at the
start of a script (and in my interactive shell) because I don't like
presuming uninitialized variables are the same as one set to NULL.
However, if this is done, the above will not detect an unitialized $1,
like the other tests will, which may be what you want, and maybe not.

Rob


More information about the colug-432 mailing list