Reputation: 3662
I tried the following solution.
if !(($str =~ ^.*[a-zA-Z0-9].*$)); then
continue;
fi
It seems there's something wrong with the syntax.
Upvotes: 1
Views: 1387
Reputation: 785276
Both your regex and syntax is incorrect. You need not use regex at all, just need glob for this:
checkStr() {
[[ $1 != *[a-zA-Z0-9]* ]]
}
This will return false
if even one alphanumeric is found in the input. Otherwise true
is returned.
Test it:
$> if checkStr 'abc'; then
echo "true case"
else
echo "false case"
fi
false case
$> if checkStr '=:() '; then
echo "true case"
else
echo "false case"
fi
true case
$> if checkStr '=:(x) '; then
echo "true case"
else
echo "false case"
fi
false case
Upvotes: 2