ot, bash programming question

Kerry Hoath kerry at gotss.net
Thu Mar 29 03:05:55 EDT 2012


You probably need something like
command you want to test
if [$? eq 0] then ... fi

Sorry i'm not good at shell scripting but $? holds the exit status and 
eq 0 tests if it is equal to 0.
You can also do command &&command 2 && command 3
to run command 2 if command 1 succeeds, then command 3 if command 2 
succeeds.

command ||other command
will run command and if it fails run other command

Regards, Kerry.
On 29/03/2012 2:45 PM, Gregory Nowak wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi folks,
>
> apologies for the off topic post, but I'm hoping someone can answer my
> question.
>
> In a bash script, how do you deal with a program returning 0 in an if
> statement?
> Here's a script to illustrate what I mean
>
> #!/bin/sh
> if [ `/bin/true || echo $?` = 1 ] ; then
> echo "returned 1"
> fi
>
> When I run this, I should just get the bash prompt back. When I run it
> though, I get:
>
> [: 4: =: unexpected operator
>
> followed by the prompt.
> I understand this happens because true exits with 0 status, and it
> isn't echoed back, so the if statement compares nothing to 1. What I'd
> like to know is how to get around that? Thanks in advance.
>
> Greg
>
>
> - -- 
> web site: http://www.romuald.net.eu.org
> gpg public key: http://www.romuald.net.eu.org/pubkey.asc
> skype: gregn1
> (authorization required, add me to your contacts list first)
>
> - --
> Free domains: http://www.eu.org/ or mail dns-manager at EU.org
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAk90BP0ACgkQ7s9z/XlyUyCQGACgxxLgwZEYcu5pvsscH4wVpBTH
> JrQAnAyQjTipfY5mHCExzyq552b7n8Fc
> =FT/Z
> -----END PGP SIGNATURE-----
> _______________________________________________
> Speakup mailing list
> Speakup at braille.uwo.ca
> http://speech.braille.uwo.ca/mailman/listinfo/speakup
>    




More information about the Speakup mailing list