<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>tcsh on
A Scripter's Notes</title><link>https://scripter.co/categories/tcsh/</link><description>Recent content in tcsh
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/tcsh/index.xml" rel="self" type="application/rss+xml"/><item><title>Installing custom fonts in Linux</title><link>https://scripter.co/installing-custom-fonts-in-linux/</link><description>&lt;p>I&amp;rsquo;ll step through how to set custom fonts for xterm terminal. My default shell is &lt;code>tcsh&lt;/code>.&lt;/p>
&lt;ol>
&lt;li>Create a folder &lt;code>.fonts&lt;/code> in your $HOME directory.&lt;/li>
&lt;li>Download fonts of your choice (&lt;strong>ttf&lt;/strong> or &lt;strong>otf&lt;/strong> format to ~/.fonts).&lt;/li>
&lt;li>Refresh the fonts cache with &lt;code>fc-cache -fv&lt;/code>.&lt;/li>
&lt;li>You can verify if your custom fonts got added to the cache using &lt;code>fc-list&lt;/code>. For example, I would do &lt;code>fc-list -f &amp;quot;%{family}\n&amp;quot; | sort -u | grep 'Inconsolata'&lt;/code>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> to check if my downloaded Inconsolata fonts got into the font cache.&lt;/li>
&lt;li>Add the below .Xdefaults snippet to your &lt;code>~/.Xdefaults&lt;/code>&lt;/li>
&lt;li>Add &lt;code>xrdb -merge $HOME/.Xdefaults&lt;/code> to your shell init script. &lt;em>My shell init script is &lt;code>~/.alias&lt;/code>&lt;/em>.&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">*customization: -color
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">XTerm*termName: xterm-256color
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*saveLines: 500
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*scrollBar: false
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*cursorColor: white
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*pointerColor: white
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*Foreground: white
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*Background: black
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*c132: true
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">xterm*loginShell: false
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">! Fonts
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">! XTerm*faceName: DejaVu Sans Mono:size=11
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">! XTerm*faceName: Inconsolata:size=11
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">! XTerm*faceName: Inconsolata\\-dz:style=dz:size=11
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">XTerm*faceName: Inconsolata\\-g:style=g:size=11
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Done! Now source your shell init script and launch &lt;code>xterm&lt;/code>.&lt;/p>
&lt;p>&lt;strong>Note&lt;/strong>: In order to use font names with hyphens in them, I had to escape them by using &lt;code>\\&lt;/code>. So for the &lt;code>Inconsolata-g&lt;/code> font, I have &lt;code>XTerm*faceName: Inconsolata\\-g:style=g:size=11&lt;/code>.&lt;/p>
&lt;p>It might be helpful to add the below aliases to your tcsh init script for quick font refresh and check, using &lt;code>fontsrefresh; fontsavail | grep 'Inconsolata'&lt;/code>.&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>fontsavail &lt;span class="s1">&amp;#39;fc-list -f &amp;#34;%{family}\n&amp;#34; | sort -u&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">alias &lt;/span>fontsrefresh &lt;span class="s1">&amp;#39;fc-cache -fv&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>You can download Inconsolata font from &lt;a href="http://levien.com/type/myfonts/inconsolata.html">here&lt;/a>.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description><category domain="https://scripter.co/categories/font">font</category><category domain="https://scripter.co/categories/linux">linux</category><category domain="https://scripter.co/categories/xterm">xterm</category><category domain="https://scripter.co/categories/tcsh">tcsh</category><guid>https://scripter.co/installing-custom-fonts-in-linux/</guid><pubDate>Thu, 27 Mar 2014 13:42:19 -0400</pubDate></item><item><title>How to remove duplicate lines using awk?</title><link>https://scripter.co/how-to-remove-duplicate-lines-using-awk/</link><description>&lt;p>If you type &lt;code>echo &amp;quot;Hi\nHow\nHi\nAre\nHi\nYou?\nAre&amp;quot;&lt;/code>, you will get this in your terminal:&lt;/p>
&lt;pre tabindex="0">&lt;code>Hi
How
Hi
Are
Hi
You?
Are
&lt;/code>&lt;/pre>&lt;p>Here&amp;rsquo;s how we can remove the duplicate lines using &lt;code>awk&lt;/code> ..&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">echo&lt;/span> &lt;span class="s2">&amp;#34;Hi\nHow\nHi\nAre\nHi\nYou?\nAre&amp;#34;&lt;/span> | awk &lt;span class="s1">&amp;#39;\!x[$0]++&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The above will give this output:&lt;/p>
&lt;pre tabindex="0">&lt;code>Hi
How
Are
You?
&lt;/code>&lt;/pre>&lt;p>The escape char &lt;code>\&lt;/code> is required for &lt;code>!&lt;/code> in tcsh.&lt;/p>
&lt;p>This is how that awk snippet works:&lt;/p>
&lt;ul>
&lt;li>Initially the x array will be empty.&lt;/li>
&lt;li>When $0 is &lt;code>Hi&lt;/code>, &lt;code>x[$0]=x[Hi]=0&lt;/code>. So &lt;code>!x[Hi]&lt;/code> will be &lt;code>True&lt;/code> and it will be printed out.&lt;/li>
&lt;li>After that the &lt;code>x[Hi]&lt;/code> becomes 1 because of the &lt;code>++&lt;/code> increment operator.&lt;/li>
&lt;li>Next time when &lt;code>$0==Hi&lt;/code>, as &lt;code>x[Hi]==1&lt;/code>, &lt;code>!x[Hi]&lt;/code> will be &lt;code>False&lt;/code> and so $0 won&amp;rsquo;t be printed out.&lt;/li>
&lt;/ul></description><category domain="https://scripter.co/categories/awk">awk</category><category domain="https://scripter.co/categories/duplicate">duplicate</category><category domain="https://scripter.co/categories/tcsh">tcsh</category><guid>https://scripter.co/how-to-remove-duplicate-lines-using-awk/</guid><pubDate>Thu, 20 Mar 2014 16:11:24 -0400</pubDate></item><item><title>Using sed</title><link>https://scripter.co/using-sed/</link><description>&lt;p>&lt;em>sed&lt;/em> stands for &lt;strong>s&lt;/strong>tream &lt;strong>ed&lt;/strong>itor.&lt;/p>
&lt;p>This is the most common way of my sed usage:&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">echo&lt;/span> &lt;span class="o">[&lt;/span>SOMETHING&lt;span class="o">]&lt;/span> | sed &lt;span class="s1">&amp;#39;s/old/NEW/g&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Based on that, I have this tcsh alias&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> to get timestamps that I use to append to quick tar backups.&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>gettimestamp &lt;span class="s1">&amp;#39;date | tr &amp;#34; :&amp;#34; &amp;#34;__&amp;#34; | sed &amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;s/_[0-9]*_EDT.*//g&amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Learn about sed from [here][s1].&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>Note how single quotes are escaped inside single-quoted alias definitions in tcsh.
[s1]: &lt;a href="http://www.grymoire.com/Unix/Sed.html">http://www.grymoire.com/Unix/Sed.html&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description><category domain="https://scripter.co/categories/sed">sed</category><category domain="https://scripter.co/categories/unix">unix</category><category domain="https://scripter.co/categories/tcsh">tcsh</category><category domain="https://scripter.co/categories/alias">alias</category><guid>https://scripter.co/using-sed/</guid><pubDate>Mon, 17 Mar 2014 09:31:29 -0400</pubDate></item><item><title>Writing aliases with optional arguments in tcsh</title><link>https://scripter.co/writing-aliases-with-optional-arguments-in-tcsh/</link><description>&lt;p>Some times I would need to define an alias in tcsh which can have
optional arguments. tcsh doesn&amp;rsquo;t seem to support that directly.&lt;/p>
&lt;p>Here&amp;rsquo;s how I solve that problem.&lt;/p>
&lt;p>If you have an alias &lt;code>alias test 'echo \!:1*'&lt;/code> and if you run &lt;code>test abc def&lt;/code>, you will get the output &lt;code>abc def&lt;/code>.&lt;/p>
&lt;p>&lt;code>!:1*&lt;/code> prints out all the arguments starting from argument 1 till the
last where even argument 1 is optional. If that argument doesn&amp;rsquo;t
exist, the variable will be assigned a null value.&lt;/p>
&lt;p>&lt;strong>But&lt;/strong> tcsh will not complain about it &amp;ndash; the &lt;code>*&lt;/code> after &lt;code>!:1&lt;/code> is
the beauty. On the other hand, if I have an alias &lt;code>alias test2 'echo \!:1'&lt;/code>, and if I run &lt;code>test&lt;/code> &amp;ndash; with zero arguments &amp;ndash; tcsh will give
an error.&lt;/p>
&lt;p>So extending that, I have the below alias defined to grab an argument
of any index.&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>opt_args &lt;span class="s1">&amp;#39;set arg1 = `echo \!:1* | awk &amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;{ print $1 }&amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;`; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> echo -n &amp;#34;Arg num 1 = $arg1 &amp;#34;; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> set arg2 = `echo \!:2* | awk &amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;{ print $1 }&amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;`; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> echo -n &amp;#34;Arg num 2 = $arg2 &amp;#34;; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> set arg3 = `echo \!:3* | awk &amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;{ print $1 }&amp;#39;&lt;/span>&lt;span class="s2">&amp;#34;&amp;#39;&amp;#34;&lt;/span>&lt;span class="s1">&amp;#39;`; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> echo -n &amp;#34;Arg num 3 = $arg3 &amp;#34;; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> echo &amp;#34;&amp;#34;; \\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> &amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>You can test this alias by running these commands:&lt;/p>
&lt;pre tabindex="0">&lt;code>opt_args abc
opt_args abc def
opt_args abc def ghi
opt_args abc def ghi jkl
&lt;/code>&lt;/pre></description><category domain="https://scripter.co/categories/tcsh">tcsh</category><category domain="https://scripter.co/categories/alias">alias</category><category domain="https://scripter.co/categories/awk">awk</category><guid>https://scripter.co/writing-aliases-with-optional-arguments-in-tcsh/</guid><pubDate>Wed, 12 Mar 2014 11:46:49 -0400</pubDate></item><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>