unix: how to tell if a string matches a regex
The standard way is to use grep
:
if echo "$arg" | grep -q -E '^[0-9]+$' kill -9 %$arg
I would suggest to use the built-in string match subcommand
if string match -r -q '^[0-9]+$' $arg echo "number!"else echo "not a number"end
Starting from version 3.2, Bash natively supports regexs, see http://www.tldp.org/LDP/abs/html/bashver3.html#REGEXMATCHREF