When I execute this
regex='^[-a-z0-9]+$'
string='abcd1--'
if [[ $string =~ $regex ] -a ![ grep - "--" ]]
then
echo "valid"
else
echo "not valid"
fi
I get
~$ sh t.sh
t.sh: line 3: syntax error in conditional expression
t.sh: line 3: syntax error near `]'
t.sh: line 3: `if [[ $string =~ $regex ] -a [ grep - "--" ]]'
~$
It is suppose to return not valid.
Can someone figure out what's wrong?
[[is incorrect.=~operator using thetestutility (which is being used by (d)ash).