![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can't interpret variable in if statement | jwholey | Shell Programming and Scripting | 4 | 06-25-2008 01:09 PM |
| Variable problem in for loop with if statement | ejdv | Shell Programming and Scripting | 6 | 06-17-2008 09:52 AM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 01:25 PM |
| Using variable in case statement | fialia | Shell Programming and Scripting | 2 | 05-12-2008 05:54 AM |
| korn shell to bash - statement not working | brdholman | UNIX for Dummies Questions & Answers | 5 | 10-15-2007 10:49 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Bash: evaluating $? variable (if statement)
Hello, i'm unable to write a correct if... statement to evaluate the $? variable.
Could anybody send to me an example? for example, this lines of code didn't work... if [ $? eq 0 ]; then etc etc if [ $? == 0 ]; then etc etc Thank you in advanced. |
|
||||
|
I'm using bash
#!/bin/bash echo "Parameter $1" echo "$?" $SCHRODINGER/utilities/reagentprep -listfull | grep $1 echo "$?" if [ $? == 1 ]then echo "Error" exit fi echo "OK" exit The output is always the same, with an incorrect (AAA) and an correct (Thiol_S_H) $1 parameter Parameter AAA 0 Checkout succeeded: MMLIBS/0722 6816 F1B7 A2A5 License file: /opt/schrodinger/license License Server: xxx@yyy.es 1 OK and Parameter Thiol_S_H 0 Checkout succeeded: MMLIBS/0722 6816 F1B7 A2A5 License file: /opt/schrodinger/license License Server: xxx@yyy.es 23 Aryl_or_Vinyl_Thiol_S_H 38 Thiol_S_H 0 OK Thankxxx!!! |
|
||||
|
And this is why we want to see the code Code:
#!/bin/bash echo "Parameter $1" echo "$?" $SCHRODINGER/utilities/reagentprep -listfull | grep $1 echo "$?" if [ $? == 1 ]then echo "Error" exit fi the if statement is evaluating the echo Condition, not the grep as intended. try instead Code:
$SCHRODINGER/utilities/reagentprep -listfull | grep $1 STATUS=$? echo "$STATUS" if [ $STATUS == 1 ]then echo "Error" exit fi |
|
||||
|
Quote:
|
|
||||
|
Quote:
Code:
if [ $? == 0 ];
then
echo "hello"
fi
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|