Re: if [[ $Something ]] – in what situations does this work?
Robert P. J. Day
rpjday at crashcourse.ca
Sat Feb 18 15:02:56 UTC 2012
On Sat, 18 Feb 2012, franz.reitinger wrote:
> First of all I suppose you're using the bash.
> Amoung others the shell treats several parameters specially; these
> parameters may only be referenced and assignement to them is not
> allowed.
>
> One of them is $?, which expands to the exit status of the most
> recently executed command. However, the exit status 0 means that the
> command has been executed without errors; any other return value has to
> be interpreted as error code.
> e.g.
> # any command ...
> if [ $? -ne 0 ]; then
> # error handling
> fi
i'd have to check but i think the constuct
if [[ $VAR ]]
does nothing but check if either that variable is defined, or if it
has a non-zero string length. so no matter what the value of $? is,
if [[ $? ]]
will always evaluate to true. you should verify that yourself,
though.
if you're checking the returned value of $?, you should always
compare it explicitly.
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
More information about the ubuntu-users
mailing list