The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 03-27-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The syntax of the assignment is all wrong. But you can avoid running the thing twice. This is one of the few situations where really you want to execute a command first, and then examine its exit code in $?

Code:
temp=`swlist -a revision 2>/dev/null | grep ABC` # note backticks, not regular quotes
case $? in 0) # grep succeeded, meaning it was found
    echo Found $temp ABC version, please remove it first ... >&2 ;;
esac
I took the liberty of removing the 2>/dev/null from grep, because I don't see how it could produce an error.

Last edited by era; 03-27-2008 at 02:39 AM.. Reason: Had inverted the success condition, oops