Good evening,
I want to write a script that will say if its argument is a number or not, however I get this:
a: 4: Syntax error: "(" unexpected (expecting ")")
At first I tried like this:
#!/bin/bash
case "$1" in
0x* ) echo hex ;;
''|*[!0-9]*) echo dec ;;
* ) echo wtf ;;
esac
Later I have found this bit:
if ! [[ "$yournumber" =~ ^[0-9]+$ ]] ; then
exec >&2; echo "error: Not a number"; exit 1
fi
Well, none of them works, I call for help!
I’m not sure what you mean by
*[!0-9]*, but the following seems to work for me.Note that
extgloblets me use the more complex pattern match to find “hex” and “dec” numbers. You can find info on this in the bash man page.