3

Number of backslashes needed for escaping regex backslash on the command-line

view full story
linux-howto

http://unix.stackexchange.com – I recently had trouble with some regex on the command-line, and found that for matching a backslash, different numbers of characters can be used. This number depends on the quoting used for the regex (none, single quotes, double quotes). See the following bash session for what I mean: echo "#ab\\cd" > file grep -E ab\cd file grep -E ab\\cd file grep -E ab\\\cd file grep -E ab\\\\cd file #ab\cd grep -E ab\\\\\cd file #ab\cd grep -E ab\\\\\\cd file #ab\cd grep -E ab\\\\\\\cd file #ab\cd grep -E ab\\\\\\\\cd file grep -E "ab\cd" file grep -E "ab\\cd" file grep -E "ab\\\cd" file #ab\cd grep - (HowTos)