For example, I have a regex to match xx-xx-xxx: [a-z0-9]{2}-[a-z0-9]{2}-[a-z0-9]{3}, I want to store it to a variable so I can keep referring to it in my program. Here is what I tried:
pattern="[a-z0-9]{2}-[a-z0-9]{2}-[a-z0-9]"
grep -i "here:$pattern" file.log # assuming that my log file has "hi:xx-xx-xxx" pattern strings.
No results are returned but if I execute:
grep -i "here:[a-z0-9]{2}-[a-z0-9]{2}-[a-z0-9]" file.log
It works. What did I do wrong?
set -xto see the interpolation of variable values as your cmd is being executed. Compare what you see there to your hard-coded version and then escape chars as need to get the same results. Good luck.set -xview and add your comments about what still is not working. Good luck.