Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
- To: MLUG Members <EMAIL:PROTECTED>
- Subject: Re: [MLUG] basic Unix pipe/exit code problem
- From: Mark Rages <EMAIL:PROTECTED>
- Date: Thu, 3 Mar 2005 17:32:53 -0600
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws;s=beta; d=gmail.com;h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references;b=M0h7ioGa66P70kMHYmZ/7QOTKsFHXWMejXrJoNSwCcF71znF7mjf0wneSdcKbZl038AU14+8eq/SWpNRMsnfTeXmiDats/mWWlW83BYJMH2+Lnor90UTxQmiaBbvtrutv6yrh7FaJlvo7r52BaZydM00Cc8gHCM9ohElITB2YTA=
- In-reply-to: <EMAIL:PROTECTED>
- References: <EMAIL:PROTECTED><EMAIL:PROTECTED><EMAIL:PROTECTED>
- Reply-to: Mark Rages <EMAIL:PROTECTED>, MLUG Members<EMAIL:PROTECTED>
- Sender: EMAIL:PROTECTED
On Thu, 3 Mar 2005 17:09:53 -0600, ryan woodsmall
<EMAIL:PROTECTED> wrote:
> >> In bash you can check the last program's return code using the
> >> variable $?. In tcsh, you can use $status.
> >
> > Would this be something Mark could use?
>
> Depends. In a lot of my scripts, I do something like the following:
>
> ###BEGIN###
>
> #!/bin/bash
> cmd1 | cmd2 | grep SOMETHING >/dev/null 2>&1
> if [ $? == 0 ] ; then
> echo found SOMETHING
> exitcode=0
> else
> if [ $? == 1 ] ; then
> echo did not find SOMETHING
> exitcode=1
> fi
> fi
> exit $exitcode
>
> ###END###
>
> Hopefully this will format correctly.
>
> This pipes commands together (cmd1 > cmd2 > grep), suppressing output.
> The return code of the final command (in this case, grep) is checked
> and preserved and an appropriate message is printed out. Finally, the
> program exits with the last command's exit value. Bash's value
> checking has to be nested because it's strictly if/then/else, not
> if/then/else if/else. Kind of ugly, but it works.
>
> This is something I use all the time, but this isn't a real example -
> you'd have to build on it.
>
Note, this doesn't solve my problem. In this example, I would want to
know if "cmd1" failed with an error.
Regards,
Mark
EMAIL:PROTECTED
--
You think that it is a secret, but it never has been one.
- fortune cookie
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members