Emacs, scripting and anything text oriented.

Escaping dollar signs in tcsh

Kaushal Modi

I found how to escape a $ sign in a regex expression in a tcsh alias. BUT it is UGLY!

I wanted to set an alias for a find command containing the -regex switch. For simplicity I will use this example:

find . -type f -regex '.*\.txt$'

This expression simply gives a list of all *.txt files in any directory under the current path.

The above command works fine when running in the terminal, but when saving that to a tcsh alias, that $ needs to be escaped:

alias findtxt "find . -type f -regex '.*txt'\"\$"''"

A simple $ has to be written as '\"\$"'!!!

Granted that I will usually get the same result if I did alias findtxt "find . -type f -regex '.*txt'" instead. But this turned out to be an interesting exercise on how to escape a $.

Reference