bash (or zsh) regular expression matching
I wanted to be able to write conditionnal on string matching in bash. One easy way to do that is :
if echo "$fic" | egrep "regexp" > /dev/null; then
echo "it matches !"
else
echo "it doesn't matches"
fi
But I found it a litle too long. This why I have written the small script match :
echo $1 | egrep $2 > /dev/null
in order to be able to write the more readable (in my point of vue) command :
if match "$fic" "regexp"; then
echo "it matches !"
else
echo "it doesn't matches"
fi
Thank you for the long version!!! It really saved my holidays, couse I had to write a script in zsh that parsed a file and nothing seems to work, expect your way to use regex.
Best regards. Lukas