unix: how to tell if a string matches a regex unix: how to tell if a string matches a regex unix unix

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