[1815825 views]

[]

Odi's astoundingly incomplete notes

New entries | Code

bash regex and quotes

[[ "a b c" =~ "a (.) c" ]]

Bash once returned the expected results from the above statement. Due to a parser change, bash now ignores reserved regex characters in the right-hand side of =~ if quotes are used, and treats them as literals. This is how to do the above now:
[[ "a b c" =~ a\ (.)\ c ]]
or
V="a b c"
RE="a (.) c"
[[ ${V} =~ ${RE} ]]

posted on 2007-05-11 17:56 UTC in Code | 1 comments | permalink
Thank you for this note.
I suppose I should have caught this in the Release Notes or something, but you are the only person to have signaled this.