I’m trying to grep stdin for a string that looks like this:
"\t", 7
The number ‘7’ is a variable, so I want to do something like this:
mumble | grep "\"\\t\", $number"
The grep isn’t returning anything. I tried to decompose this in to its simplest terms:
$ echo '"\t"'
"\t"
… as expected.
$ echo "\"\\t\""
"\t"
This renders the string that I want when interpolated in double quotes. But…
$ echo '"\t"' | grep "\"\\t\""
doesn’t return anything.
Ok, let’s turn on set -x to see what bash thinks is going on…
$ echo '"\t"' | grep "\"\\t\""
+ grep '"\t"'
+ echo '"\t"'
… so I’m grepping for exactly what’s being echoed… and single quotes aren’t special characters in basic regex, so why isn’t grep matching this?
1 Answer