On the right-hand side of the [[ x =~ y ]] test, quoted/escaped strings are viewed as literal, and unquoted strings are considered regular expressions. So any of the following will work:
[[ "$argum" =~ \$ ]]
[[ "$argum" =~ "$" ]]
[[ "$argum" =~ '$' ]]
[[ "$argum" =~ [$] ]]
And believe it or not, this should also work:
[[ "$argum" =~ "\$" ]]
This is due to the nature of double-quoting. Inside them, \$
escapes to a literal $
, so it again works as expected. See the quoting
section of the bash man page for details.
These will not work correctly:
[[ "$argum" =~ '\$' ]] # treated as the literal string \$
[[ "$argum" =~ $ ]] # treated as the "end of line" regex
If you can't get any of these patterns to do the job correctly, then your problem likely lies somewhere else. I tried your above script and it works perfectly for me too.