$regexdoes not expand as it is single. In bash, decompositions are performed only in double lines:
foo="bar"
echo '$foo'
echo "$foo"
So just fold your line like this:
'!'"/$regex/"
and he will behave as you expect. !should not be evaluated, as this will execute the last command in your story.
source
share