Say you have the user enter in a number 0-3 and want to test it. The most common way seems to be:
[[ $var =~ ^[0-3]$ ]]
But how would you use this with:
test expression
My initial attempt doesn't evaluate correctly, e.g.
read -p "Enter selection [0-3] > "
if test $REPLY == '^[0-3]$' ; then
...
It just evaluates the if statement as false.
testcommand does not support regular expressions. useexprinstead: stackoverflow.com/questions/7159441/…test "$var" = 0 || test "$var" = 1 || test "$var" = 2 || test "$var" = 3 && echo okay