Reputation: 5684
I am unable to store a particular regex in a variable in bash.
regex=".*(w1|w2|w3|w4).*"
echo $regex
Expected Output:
.*(w1|w2|w3|w4).*
Actual Output:
..
How do I resolve this?
Upvotes: 0
Views: 45
Reputation: 545588
It’s stored correctly. The issue is that you’re using the variable incorrectly: you must quote the variable, otherwise the result gets expanded by the shell, and interpreted as a shell glob.
So, use
echo "$regex"
Upvotes: 2