I am passing command line arguments to a shell script and it is being compared aganist a regular expression. The following code is case-sensitive:
[[ $1 =~ ^(cat)|(dog)$ ]] && echo "match" || echo "no match"
How can I modify this regex that will ignore cases? I would be able to pass cAt
and it should match.
I want to use /i
regex flag as it ignores cases. But how do I use it inside a shell script? I have tried [[ $1 =~ /(cat)|(dog)/i ]]
but the script exited with a syntax error.
StackOverflow has a similar question but it does not answer my inquiry. I want to use test
to compare both strings and not interested to use shopt -s nocasematch
or grep <expression>