Re: if [[ $Something ]] – in what situations does this work?
Johnny Rosenberg
gurus.knugum at gmail.com
Sat Feb 18 14:53:35 UTC 2012
2012/2/18 franz.reitinger <franz.reitinger at htl-wels.at>:
> First of all I suppose you're using the bash.
Yes, sorry for not mentioning that.
> Amoung others the shell treats several parameters specially; these
> parameters may only be referenced and assignement to them is not allowed.
But I didn't assign anything to it, did I?
>
> 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.
Yes, but [[ $? ]] returns the same result no matter the value of $?,
so [[ $Something ]] doesn't seem to be a valid syntax, is it? Maybe I
just confuse bash scripting with other things, such as C and even
Basic:
if (x) {
dostuff;
domorestuff;
}
or
if x then
dostuff
domorestuff
endif
> e.g.
> # any command ...
> if [ $? -ne 0 ]; then
> # error handling
> fi
I suppose ”if [[ $? == 0 ]]” is equal to ”if [ $? -ne 0 ]”, right? And
I think that even ”if [[ $? = 0 ]]” is allowed and means the same
thing, as far as I have seen.
Kind regards
Johnny Rosenberg
ジョニー・ローゼンバーグ
>
> /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).
> ************************************************************
> */
>
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
More information about the ubuntu-users
mailing list