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.
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.
This code works fine for me.
if [ $? == 0 ]
then
echo "hello"
else
echo "goobye"
fi
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
#!/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
$SCHRODINGER/utilities/reagentprep -listfull | grep $1
STATUS=$?
echo "$STATUS"
if [ $STATUS == 1 ]then
echo "Error"
exit
fi
Are you giving proper space after and before the brackets like this
if [ $? == 0 ];
then
echo "hello"
fi
Shame on me... thank you very much!!!