bug-bash
[Top][All Lists]
Advanced

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

Re: null command and parameter expansion for "Display error if null or u


From: Bob Proulx
Subject: Re: null command and parameter expansion for "Display error if null or unset"
Date: Mon, 31 Jul 2006 21:49:09 -0600
User-agent: Mutt/1.5.9i

Poor Yorick wrote:
> The following line does not perform the "echo" command.
> 
> : ${FAKEVAR?} || echo hello
> 
> This seems inconsistent, since the return status is set to one, not
> to mention that the null command is documented to return a zero exit
> code.  It would be a convenient and concise syntax for acting on
> unset variables.

It is, however, as documented and compatible with the legacy (the old
Bourne shell behaved this way too) and POSIX shells.

  `${PARAMETER:?WORD}'
       If PARAMETER is null or unset, the expansion of WORD (or a message
       to that effect if WORD is not present) is written to the standard
       error and the shell, if it is not interactive, exits.  Otherwise,
       the value of PARAMETER is substituted.

Because the shell exits the right hand side of the or is not executed.

Try this:

  ( : ${FAKEVAR?} ) || echo hello

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]