Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Robert Nichols
On 05/30/2011 05:14 PM, fred smith wrote: > Yes, all commands return a value UNLESS it was written by one of the > idi,... er, misguided programmers who thinks its ok to write (in > C): > > void main (void) > { > ... > exit(); > } > > because, of course, in C main() always r

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Dotan Cohen
On Tue, May 31, 2011 at 01:14, fred smith wrote: > Yes, all commands return a value UNLESS it was written by one of the > idi,... er, misguided programmers who thinks its ok to write (in > C): > > void main (void) >        { >        ... >        exit(); >        } > > because, of course, in C mai

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread fred smith
On Mon, May 30, 2011 at 05:38:56PM +0300, Dotan Cohen wrote: > All commands return a value, usually 0 if run properly. For instance, try: > $ ls && echo "done" > $ lsd && echo "done" > > The echo command is only executed if the ls command exited > successfully. If one did not add the echo command

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Stephen Harris
On Mon, May 30, 2011 at 11:24:19AM -0500, Robert Nichols wrote: > $ true | false | false | true | true > $ echo ${PIPESTATUS[*]} > 0 1 1 0 0 Note that this is bash-ism; don't depend on it in a POSIX environment! -- rgds Stephen ___ Cent

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Robert Nichols
On 05/30/2011 10:00 AM, Dotan Cohen wrote: > On Mon, May 30, 2011 at 17:55, Bob Beers wrote: >> You can check the return code. >> >> $ ls >> $ echo $? >> >> 0 (usually) indicates success. >> > > Thank you Bob, that is exactly what I was looking for! And when you have several commands in a pipelin

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Dotan Cohen
On Mon, May 30, 2011 at 18:05, Ljubomir Ljubojevic wrote: > Take notice that you can use $? *only* once. So if you ever need to > reuse that status, you must first assign exit code to a variable and > then evaluate variable. > Actually, that was kink of obvious to me, but good thing that you poin

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Dotan Cohen
On Mon, May 30, 2011 at 17:59, Christopher J. Buckley wrote: > Have a read up on using return codes in Bash. > http://tldp.org/LDP/abs/html/exit-status.html Thanks, Chris, the link was very informative. I should spend more time at the tldp site, I know. -- Dotan Cohen http://gibberish.co.il h

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Ljubomir Ljubojevic
Dotan Cohen wrote: > On Mon, May 30, 2011 at 17:55, Bob Beers wrote: >> You can check the return code. >> >> $ ls >> $ echo $? >> >> 0 (usually) indicates success. >> > > Thank you Bob, that is exactly what I was looking for! > > > Take notice that you can use $? *only* once. So if you ever ne

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Keith Roberts
On Mon, 30 May 2011, Christopher J. Buckley wrote: > To: CentOS mailing list > From: Christopher J. Buckley > Subject: Re: [CentOS] Getting the return value of the last command run > > Have a read up on using return codes in Bash. > > http://tldp.org/LDP/abs/html/exit-

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Dotan Cohen
On Mon, May 30, 2011 at 17:55, Bob Beers wrote: > You can check the return code. > > $ ls > $ echo $? > > 0 (usually) indicates success. > Thank you Bob, that is exactly what I was looking for! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Christopher J. Buckley
Have a read up on using return codes in Bash. http://tldp.org/LDP/abs/html/exit-status.html Quick example: #!/bin/bash ls foobar if [ $? -eq 0 ] ; then echo "successful" else echo "not successful" fi You get the idea.. Cheer

Re: [CentOS] Getting the return value of the last command run

2011-05-30 Thread Bob Beers
On Mon, May 30, 2011 at 10:38 AM, Dotan Cohen wrote: > All commands return a value, usually 0 if run properly. For instance, try: > $ ls && echo "done" > $ lsd && echo "done" > > The echo command is only executed if the ls command exited > successfully. If one did not add the echo command with the

[CentOS] Getting the return value of the last command run

2011-05-30 Thread Dotan Cohen
All commands return a value, usually 0 if run properly. For instance, try: $ ls && echo "done" $ lsd && echo "done" The echo command is only executed if the ls command exited successfully. If one did not add the echo command with the && after a command, how can he determine if the command exited s