I'm trying to use Bash replacement to replace the whole string in variable if it matches a pattern. For example:
pattern="ABCD"
${var/pattern/}
removes (replaces with nothing) the first occurrence of $pattern
in $var
${var#pattern}
removes $pattern
in the beginning of $var
But how can I remove regex pattern "^ABCD$"
from $var
? I could:
if [ $var == "ABCD" ] ; then
echo "This is a match." # or whatever replacement
fi
but that's quite what I'm looking for.