<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>escaping on
A Scripter's Notes</title><link>https://scripter.co/categories/escaping/</link><description>Recent content in escaping
on A Scripter's Notes</description><language>en-us</language><managingEditor>kaushal.modi@gmail.com (Kaushal Modi)</managingEditor><webMaster>kaushal.modi@gmail.com (Kaushal Modi)</webMaster><lastBuildDate>Wed, 22 Apr 2026 08:24:58 -0400</lastBuildDate><generator>Hugo -- gohugo.io</generator><docs>https://validator.w3.org/feed/docs/rss2.html</docs><atom:link href="https://scripter.co/categories/escaping/index.xml" rel="self" type="application/rss+xml"/><item><title>Escaping dollar signs in tcsh</title><link>https://scripter.co/escaping-dollar-signs-in-tcsh/</link><description>&lt;p>I found how to escape a $ sign
in a regex expression in a tcsh alias. BUT it is UGLY!&lt;/p>
&lt;p>I wanted to set an alias for a &lt;code>find&lt;/code> command containing the &lt;code>-regex&lt;/code>
switch. For simplicity I will use this example:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-tcsh" data-lang="tcsh">&lt;span class="line">&lt;span class="cl">find . -type f -regex &lt;span class="s1">&amp;#39;.*\.txt$&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This expression simply gives a list of all *.txt files in any
directory under the current path.&lt;/p>
&lt;p>The above command works fine when running in the terminal, but when
saving that to a &lt;code>tcsh&lt;/code> alias, that &lt;code>$&lt;/code> needs to be escaped:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-tcsh" data-lang="tcsh">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">alias &lt;/span>findtxt &lt;span class="s2">&amp;#34;find . -type f -regex &amp;#39;.*txt&amp;#39;\&amp;#34;\$&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;&amp;#39;&lt;/span>&lt;span class="err">&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>A simple &lt;code>$&lt;/code> has to be written as &lt;code>'\&amp;quot;\$&amp;quot;'&lt;/code>!!!&lt;/p>
&lt;/blockquote>
&lt;p>Granted that I will usually get the same result if I did &lt;code>alias findtxt &amp;quot;find . -type f -regex '.*txt'&amp;quot;&lt;/code> instead. But this turned out
to be an interesting exercise on how to escape a &lt;code>$&lt;/code>.&lt;/p>
&lt;p>&lt;a href="https://stackoverflow.com/questions/3571743/csh-alias-with-perl-one-liner-evaluates-when-alias-is-created-and-not-when-alias">Reference&lt;/a>&lt;/p></description><category domain="https://scripter.co/categories/tcsh">tcsh</category><category domain="https://scripter.co/categories/find">find</category><category domain="https://scripter.co/categories/escaping">escaping</category><category domain="https://scripter.co/categories/regex">regex</category><guid>https://scripter.co/escaping-dollar-signs-in-tcsh/</guid><pubDate>Thu, 06 Mar 2014 16:12:56 -0500</pubDate></item></channel></rss>