if [[ $Something ]] – in what situations does this work?

franz.reitinger franz.reitinger at htl-wels.at
Sat Feb 18 13:59:41 UTC 2012


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

/franzR
On Sat, 18 Feb 2012 13:56:50 +0100, Johnny Rosenberg wrote:
> I tried this with the $? variable, but failed. Seems like [[ $? ]] is
> always true no matter the value of $?. [[ $? == 0 ]] seems to work,
> though.
>
> I thought that ”if [[ $? ]]” means ”if $? is True”. What is True
> anyway? 0? 1? Anything but 0?
>
> I am not sure what I am asking for here, but any kind of input in the
> subject is welcome. Thanks.
>
>
> Kind regards
>
> Johnny Rosenberg
> ジョニー・ローゼンバーグ
/* 
 ************************************************************
 * Mail checked by Avira virus scanner (mail.htl-wels.at).
 ************************************************************
*/

 




More information about the ubuntu-users mailing list