[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (no subject)
From: |
Chris F.A. Johnson |
Subject: |
Re: (no subject) |
Date: |
Mon, 31 Jul 2006 13:06:14 -0400 |
User-agent: |
slrn/0.9.8.1 (Linux) |
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)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: (no subject),
Chris F.A. Johnson <=