1

Comparison treating strings as zero integers

view story
linux-howto

http://www.unix.com – I'm trying to write a bash script to perform basic arithmetic operations but I want to run a comparison on the arguments first to check that they're a number greater than zero. I want an error to pop up if the arguments args aren't >= 0 so I have: Code: if ! [[ $1 -ge 0 ]]; then echo "bad number: $1" fi But whenever I type in something like "blah + 9" it should tell me "bad number: blah", instead it treats "blah" as a zero and it gives the output as 9. If I use -gt 0 it eliminates the "blah" but also doesn't let me use zeros. (HowTos)