Input:
number=5
if $number > 0; echo "Yes"; else echo "No";fi
My output is:
bash: 5: command not found...
No
I only want Yes or No, so what's wrong with the syntax?
if requires a command (actually, a command list), not an expression. The test command is what you want. (You are also missing the then keyword, which terminates the condition.)
if test "$number" -gt 0; then
echo "Yes"
else
echo "No"
fi
For bash arithmetic, prefer modern style :
if ((number > 0)); then
echo "Yes"
else
echo "No"
fi
or using boolean logic :
((number > 0)) && echo "Yes" || echo "No"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With