How do I ask "if NOT" in shell?

Chip Salzenberg chip at ateng.com
Sat Oct 28 04:23:14 AEST 1989


Several people, including Dave Hitz, suggest variations on:

    NOT() {
	${1+"$@"}
	test $? -ne 0
    }

I love it!  It's simple and it works.  However, Dave Hitz asserts:

>Picky people may observe that the arguments to NOT get expanded by
>the shell twice, but I've never been caught by this.

In fact, they do not get expanded twice.  The effect of "$@", as opposed to
"$*", is to expand the shell function's arguments as if they were
_individually_ quoted.  Thus they will not be expanded (again) in the shell
function.

Unfortunately, if $# is zero, "$@" expands to "" instead of nothing.  Thus
the need for the ${1+"$@"} hack.  [sigh]
-- 
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering;  <chip at ateng.com> or <uunet!ateng!chip>
"'Why do we post to Usenet?'  Naturally, the answer is, 'To get a response.'"
                        -- Brad "Flame Me" Templeton



More information about the Comp.unix.questions mailing list