Reputation: 577
So I am trying to test a few things coding in bash. As a n00b I am having some problems with the basics and how irritating it can get using shell dealing with numbers.
if $((echo $?)) > 0 ;then
echo "there is an error";
else
echo "it passed";
fi
the error I get is : bash: echo 0: syntax error in expression (error token is "0")
I tried without the echo and I get: bash: ./0: Permission denied
so I am a bit confused what the shell is trying to do.
Thanks
Upvotes: 1
Views: 2809
Reputation: 195239
try this:
OUT=$?
if [ $OUT -eq 0 ];then
echo "OK!"
else
echo "NOT OK!"
fi
Upvotes: 0
Reputation: 7235
The whole arithmetic evaluation must be within double parentheses:
if (($? > 0)) ;then
echo "there is an error";
else
echo "it passed";
fi
Upvotes: 2