I have the following check:
if [[ "$abc" =~ ^((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([A-Za-z0-9.@:_/-]+)\.com(:[0-9]+)?\/([A-Za-z0-9.@:_/-]+)\/([a-zA-Z0-9_]+)(\.git)(\/)?$ ]]; then
die "Invalid"
fi
It does not really matter what it checks, I just want to get rid of the =~ operator. I have a basic static test of the scripts:
for file in $filelist
do
echo -n "Checking $file..."
bash -n $file
echo "OK"
done
Due to the =~ operator, it gets an error:
syntax error in conditional expression: unexpected token `('
script: line 847: syntax error near `^(('
Even though, when I execute the script itself, I don't get that error.
I guess the error is due to not wrapping ^((git|ssh|http(s)?)|(git@[\w\.]+))(:(\/\/)?)([A-Za-z0-9.@:_/-]+)\.com(:[0-9]+)?\/([A-Za-z0-9.@:_/-]+)\/([a-zA-Z0-9_]+)(\.git)(\/)?$ with apostrophes. If I do wrap it, it will not enter the if statement.
So I'm looking to replace the =~. What is the proper way to do so?
fooand ranbash -n fooand it completed without errors.=~and not a problem with the regex itself. I updated the full regex. It a problem with the regex?