MLUG: Re: [MLUG] basic Unix pipe/exit code problem
Re: [MLUG] basic Unix pipe/exit code problem
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
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