Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Ubuntu User (http://www.linux-archive.org/ubuntu-user/)
-   -   if – in what situations does this work? (http://www.linux-archive.org/ubuntu-user/634653-if-what-situations-does-work.html)

Johnny Rosenberg 02-18-2012 11:56 AM

if – in what situations does this work?
 
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
ジョニー・*ーゼンバーグ

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

"franz.reitinger" 02-18-2012 12:59 PM

if – in what situations does this work?
 
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).
************************************************** **********
*/



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users


All times are GMT. The time now is 04:05 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.