Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix if condition 1

Status
Not open for further replies.

cisco999

Programmer
Apr 26, 2001
66
US
In the following code excerpt, please explain [ $? = 0 ] in the first if condition. Thank you.

java -XdoCloseWithReadPending -classpath .:UKtest.jar:DemandSchedule20.jar:$JDBC_PATH/classes111.zip hmi.common.uk.PullSignalConfirmExtract $ukFile $prod 2>err.out >> $LOGFILE
if [ $? = 0 ]
then
if [[ -s $ukFile ]]
then
. ukPricing_ftp.sh $ukServer $ukUser $ukPassword $ukFile mysign/$ukFile
grep -q '226 Transfer complete.' ftp.log
if [ $? -ne 0 ]
then
cat ftp.log | mailx -s " UK Pull Signal Confirm Extract: ftp to UK failed" ec_team@test.com
mv $ukFile $ukDir/data/error/$ukFile.$timestamp
else
mv $ukFile $ukDir/data/log/$ukFile.$timestamp
fi
else
echo "Nothing to extract. File has no data."
rm -f $ukFile
fi
else
cat err.out | mailx -s " UK Pull Signal Confirm Extract: Java Load failed" ec_team@test.com
mv $ukFile $ukDir/data/error/$ukFile.$timestamp
fi
 
if [$? = 0] ask if the result of the las command was successful.

$? is the return code of the last command issued. It depend of the last command. example, a script can have an "exit 0" as the exit command, so $? will be 0, *but* if the exit command is another one, e.g. "exit 1" the $? will be 1.

ussualy, exit code 0 tells you that the command was finished sucessfuly.

Cheers,

Chacal, Inc.[wavey]
 
Thanks very much! The next if condition uses double brackets, [[ ]], what does that indicate? Do you have any websites that you would recommend for a beginner dealing with UNIX scripts?
 
THE starting point:
man yourshell
ie:
man ksh
man bash

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top