On 2006-07-31, Poor Yorick wrote:
> The following command does not echo "hello".
>
>: ${FAKEVAR?} || echo hello
>
> This seems inconsistent, since the return status is set to 1. It
> would be a convenient and concise syntax for acting on unset
> variables.

      If the variable is not set, "the shell, if it is not
      interactive, exits", and thus cannot execute the rest of the
      line. The expansion failed, so an error is returned.

      The "convenient and concise syntax for acting on unset
      variables" is:

: ${FAKEVAR?hello}

      Or, if you do not want to exit the script:

[ -n "${FAKEVAR+X" ] || echo hello

-- 
   Chris F.A. Johnson                      <http://cfaj.freeshell.org>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to