Dojo
Dojo

Reputation: 5684

Can't store this regex in a variable

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

Answers (1)

Konrad Rudolph
Konrad Rudolph

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

Related Questions