What does this ( if [$? -ne 0] ) mean in unix ? Linux
Posted by
Jiltin 6 February, 2009 3,435 views
- How can we find the receipts related to a transmission?
- Paymentech file comparison in Linux
- Oracle applications (11i) Invalid credit cards in bank records report
- How To Extract,Using Bash/Unix/Linux Shell Scripting, The Oracle Data Like Excel Report And Send As Email Attachment?
- BASH Help:How do i check if a directory exists and display that it doesn’t using bash?
$? is the return code form a previous command or function
in unix, 0 is the standard return code for a successful completion
if [$? -ne 0]
The whole line means
‘if the previous return code was not equal to 0 ‘ ….
It will then be followed by
then
statement # do something
(optional) else
(optional) statement # do something else
fi # closure of the ‘if’ conditional
For example
scp filename login@hostname:filename
if [ $? -ne 0 ]
then
echo "Error Occured While SCP"
else
echo "———————————————————"
echo "successful transmission "
echo "———————————————————"
fi
if [ $? -ne 0 ]
then
echo "Error Occured While SCP"
else
echo "———————————————————"
echo "successful transmission "
echo "———————————————————"
fi
Categories :
Scripts Unix

Comments
No comments yet.