I want to write a bash script that takes an input string and if it doesn't contain a particular tag in the beginning, add the tag to the beginning. The following is the script I wrote
#! /bin/bash
message=$1
tag="hello"
filter="^$tag.*"
if [[ ! $message =~ $filter ]]; then
message="$tag $message"
fi
echo $message
This works well as long as the tag doesn't contain a regular expression specific keyword.
For example if the tag was set to [hello] the filter doesn't work since the square bracket is a keyword.
How to change the filter so that it ignores any keywords containing in the tag?