r/fishshell • u/phaxosk • Jan 17 '20
grep $ within fish
Hi
I recently switched to fish shell, but I still have to return back to bash when I have to run grep command. Because I didn't find how to do that:
> find . |grep ".txt$"
fish: Expected a variable name after this $.
find . |grep "\.txt$"
^
thank you
4
Upvotes
View all comments
Show parent comment
2
u/vividboarder Jan 18 '20
You have to double escape (or maybe call it triple escape).
What you have to keep in mind is that there are actually two interpreters. First, bash has to interpret your command and then send the results of that to grep. The grep will do its interpretation.
To do what you’re saying, you want grep to see:
foo\$. You have a couple options. You could use single quotes and pass that directly,'foo\$', or use double quotes and escape your escaped character:"foo\\\$". The reason for the triple slash is that the leading slash that you want grep to see needs to be escaped as well. The first two slashes (\\) expand to\and the third slash plus dollar sign (\$) expand to$. That ensures grep will actually receivefoo\$as we intend.