<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.101.0">Hugo</generator><title type="html">tcsh on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/categories/tcsh/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/categories/tcsh/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/categories/tcsh/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/categories/tcsh/jf2feed.json" rel="alternate" type="application/jf2feed+json" title="jf2feed"/><updated>2026-04-22T08:24:57-04:00</updated><author><name>Kaushal Modi</name><email>kaushal.modi@gmail.com</email></author><id>https://scripter.co/categories/tcsh/</id><entry><title type="html">Installing custom fonts in Linux</title><link href="https://scripter.co/installing-custom-fonts-in-linux/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/installing-custom-fonts-in-linux/</id><published>2014-03-27T13:42:19-04:00</published><updated>2014-03-27T13:42:19-04:00</updated><content type="html"><![CDATA[<p>I&rsquo;ll step through how to set custom fonts for xterm terminal. My default shell is <code>tcsh</code>.</p>
<ol>
<li>Create a folder <code>.fonts</code> in your $HOME directory.</li>
<li>Download fonts of your choice (<strong>ttf</strong> or <strong>otf</strong> format to ~/.fonts).</li>
<li>Refresh the fonts cache with <code>fc-cache -fv</code>.</li>
<li>You can verify if your custom fonts got added to the cache using <code>fc-list</code>. For example, I would do <code>fc-list -f &quot;%{family}\n&quot; | sort -u | grep 'Inconsolata'</code><sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> to check if my downloaded Inconsolata fonts got into the font cache.</li>
<li>Add the below .Xdefaults snippet to your <code>~/.Xdefaults</code></li>
<li>Add <code>xrdb -merge $HOME/.Xdefaults</code> to your shell init script. <em>My shell init script is <code>~/.alias</code></em>.</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">*customization: -color
</span></span><span class="line"><span class="cl">XTerm*termName: xterm-256color
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">xterm*saveLines:        500
</span></span><span class="line"><span class="cl">xterm*scrollBar:        false
</span></span><span class="line"><span class="cl">xterm*cursorColor:      white
</span></span><span class="line"><span class="cl">xterm*pointerColor:     white
</span></span><span class="line"><span class="cl">xterm*Foreground:       white
</span></span><span class="line"><span class="cl">xterm*Background:       black
</span></span><span class="line"><span class="cl">xterm*c132:             true
</span></span><span class="line"><span class="cl">xterm*loginShell:       false
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">! Fonts
</span></span><span class="line"><span class="cl">! XTerm*faceName: DejaVu Sans Mono:size=11
</span></span><span class="line"><span class="cl">! XTerm*faceName: Inconsolata:size=11
</span></span><span class="line"><span class="cl">! XTerm*faceName: Inconsolata\\-dz:style=dz:size=11
</span></span><span class="line"><span class="cl">XTerm*faceName: Inconsolata\\-g:style=g:size=11
</span></span></code></pre></div><p>Done! Now source your shell init script and launch <code>xterm</code>.</p>
<p><strong>Note</strong>: In order to use font names with hyphens in them, I had to escape them by using <code>\\</code>. So for the <code>Inconsolata-g</code> font, I have <code>XTerm*faceName: Inconsolata\\-g:style=g:size=11</code>.</p>
<p>It might be helpful to add the below aliases to your tcsh init script for quick font refresh and check, using <code>fontsrefresh; fontsavail | grep 'Inconsolata'</code>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl"><span class="nb">alias </span>fontsavail   <span class="s1">&#39;fc-list -f &#34;%{family}\n&#34; | sort -u&#39;</span>
</span></span><span class="line"><span class="cl"><span class="nb">alias </span>fontsrefresh <span class="s1">&#39;fc-cache -fv&#39;</span>
</span></span></code></pre></div><div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>You can download Inconsolata font from <a href="http://levien.com/type/myfonts/inconsolata.html">here</a>.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>]]></content><category scheme="https://scripter.co/categories/font" term="font" label="font"/><category scheme="https://scripter.co/categories/linux" term="linux" label="linux"/><category scheme="https://scripter.co/categories/xterm" term="xterm" label="xterm"/><category scheme="https://scripter.co/categories/tcsh" term="tcsh" label="tcsh"/></entry><entry><title type="html">How to remove duplicate lines using awk?</title><link href="https://scripter.co/how-to-remove-duplicate-lines-using-awk/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/how-to-remove-duplicate-lines-using-awk/</id><published>2014-03-20T16:11:24-04:00</published><updated>2014-03-20T16:11:24-04:00</updated><content type="html"><![CDATA[<p>If  you type <code>echo &quot;Hi\nHow\nHi\nAre\nHi\nYou?\nAre&quot;</code>, you will get this in your terminal:</p>
<pre tabindex="0"><code>Hi
How
Hi
Are
Hi
You?
Are
</code></pre><p>Here&rsquo;s how we can remove the duplicate lines using <code>awk</code> ..</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;Hi\nHow\nHi\nAre\nHi\nYou?\nAre&#34;</span> |  awk <span class="s1">&#39;\!x[$0]++&#39;</span>
</span></span></code></pre></div><p>The above will give this output:</p>
<pre tabindex="0"><code>Hi
How
Are
You?
</code></pre><p>The escape char <code>\</code> is required for <code>!</code> in tcsh.</p>
<p>This is how that awk snippet works:</p>
<ul>
<li>Initially the x array will be empty.</li>
<li>When $0 is <code>Hi</code>, <code>x[$0]=x[Hi]=0</code>. So <code>!x[Hi]</code> will be <code>True</code> and it will be printed out.</li>
<li>After that the <code>x[Hi]</code> becomes 1 because of the <code>++</code> increment operator.</li>
<li>Next time when <code>$0==Hi</code>, as <code>x[Hi]==1</code>, <code>!x[Hi]</code> will be <code>False</code> and so $0 won&rsquo;t be printed out.</li>
</ul>]]></content><category scheme="https://scripter.co/categories/awk" term="awk" label="awk"/><category scheme="https://scripter.co/categories/duplicate" term="duplicate" label="duplicate"/><category scheme="https://scripter.co/categories/tcsh" term="tcsh" label="tcsh"/></entry><entry><title type="html">Using sed</title><link href="https://scripter.co/using-sed/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/using-sed/</id><published>2014-03-17T09:31:29-04:00</published><updated>2014-03-17T09:31:29-04:00</updated><content type="html"><![CDATA[<p><em>sed</em> stands for <strong>s</strong>tream <strong>ed</strong>itor.</p>
<p>This is the most common way of my sed usage:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="o">[</span>SOMETHING<span class="o">]</span> | sed <span class="s1">&#39;s/old/NEW/g&#39;</span>
</span></span></code></pre></div><p>Based on that, I have this tcsh alias<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> to get timestamps that I use to append to quick tar backups.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl"><span class="nb">alias </span>gettimestamp <span class="s1">&#39;date | tr &#34; :&#34; &#34;__&#34; | sed &#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;s/_[0-9]*_EDT.*//g&#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;&#39;</span>
</span></span></code></pre></div><p>Learn about sed from [here][s1].</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>Note how single quotes are escaped inside single-quoted alias definitions in tcsh.
[s1]: <a href="http://www.grymoire.com/Unix/Sed.html">http://www.grymoire.com/Unix/Sed.html</a>&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>]]></content><category scheme="https://scripter.co/categories/sed" term="sed" label="sed"/><category scheme="https://scripter.co/categories/unix" term="unix" label="unix"/><category scheme="https://scripter.co/categories/tcsh" term="tcsh" label="tcsh"/><category scheme="https://scripter.co/categories/alias" term="alias" label="alias"/></entry><entry><title type="html">Writing aliases with optional arguments in tcsh</title><link href="https://scripter.co/writing-aliases-with-optional-arguments-in-tcsh/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/writing-aliases-with-optional-arguments-in-tcsh/</id><published>2014-03-12T11:46:49-04:00</published><updated>2014-03-12T11:46:49-04:00</updated><content type="html"><![CDATA[<p>Some times I would need to define an alias in tcsh which can have
optional arguments. tcsh doesn&rsquo;t seem to support that directly.</p>
<p>Here&rsquo;s how I solve that problem.</p>
<p>If you have an alias <code>alias test 'echo \!:1*'</code> and if you run <code>test abc def</code>, you will get the output <code>abc def</code>.</p>
<p><code>!:1*</code> prints out all the arguments starting from argument 1 till the
last where even argument 1 is optional.  If that argument doesn&rsquo;t
exist, the variable will be assigned a null value.</p>
<p><strong>But</strong> tcsh will not complain about it &ndash; the <code>*</code> after <code>!:1</code> is
the beauty. On the other hand, if I have an alias <code>alias test2 'echo \!:1'</code>, and if I run <code>test</code> &ndash; with zero arguments &ndash; tcsh will give
an error.</p>
<p>So extending that, I have the below alias defined to grab an argument
of any index.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl"><span class="nb">alias </span>opt_args <span class="s1">&#39;set arg1 = `echo \!:1* | awk &#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;{ print $1 }&#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;`; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">                echo -n &#34;Arg num 1 = $arg1 &#34;; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">                set arg2 = `echo \!:2* | awk &#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;{ print $1 }&#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;`; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">                echo -n &#34;Arg num 2 = $arg2 &#34;; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">                set arg3 = `echo \!:3* | awk &#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;{ print $1 }&#39;</span><span class="s2">&#34;&#39;&#34;</span><span class="s1">&#39;`; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">                echo -n &#34;Arg num 3 = $arg3 &#34;; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">                echo &#34;&#34;; \\
</span></span></span><span class="line"><span class="cl"><span class="s1">               &#39;</span>
</span></span></code></pre></div><p>You can test this alias by running these commands:</p>
<pre tabindex="0"><code>opt_args abc
opt_args abc def
opt_args abc def ghi
opt_args abc def ghi jkl
</code></pre>]]></content><category scheme="https://scripter.co/categories/tcsh" term="tcsh" label="tcsh"/><category scheme="https://scripter.co/categories/alias" term="alias" label="alias"/><category scheme="https://scripter.co/categories/awk" term="awk" label="awk"/></entry><entry><title type="html">Escaping dollar signs in tcsh</title><link href="https://scripter.co/escaping-dollar-signs-in-tcsh/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://scripter.co/escaping-dollar-signs-in-tcsh/</id><published>2014-03-06T16:12:56-05:00</published><updated>2014-03-06T16:12:56-05:00</updated><content type="html"><![CDATA[<p>I found how to escape a $ sign
in a regex expression in a tcsh alias. BUT it is UGLY!</p>
<p>I wanted to set an alias for a <code>find</code> command containing the <code>-regex</code>
switch. For simplicity I will use this example:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl">find . -type f -regex <span class="s1">&#39;.*\.txt$&#39;</span>
</span></span></code></pre></div><p>This expression simply gives a list of all *.txt files in any
directory under the current path.</p>
<p>The above command works fine when running in the terminal, but when
saving that to a <code>tcsh</code> alias, that <code>$</code> needs to be escaped:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-tcsh" data-lang="tcsh"><span class="line"><span class="cl"><span class="nb">alias </span>findtxt <span class="s2">&#34;find . -type f -regex &#39;.*txt&#39;\&#34;\$&#34;</span><span class="s1">&#39;&#39;</span><span class="err">&#34;</span>
</span></span></code></pre></div><blockquote>
<p>A simple <code>$</code> has to be written as <code>'\&quot;\$&quot;'</code>!!!</p>
</blockquote>
<p>Granted that I will usually get the same result if I did <code>alias findtxt &quot;find . -type f -regex '.*txt'&quot;</code> instead. But this turned out
to be an interesting exercise on how to escape a <code>$</code>.</p>
<p><a href="https://stackoverflow.com/questions/3571743/csh-alias-with-perl-one-liner-evaluates-when-alias-is-created-and-not-when-alias">Reference</a></p>]]></content><category scheme="https://scripter.co/categories/tcsh" term="tcsh" label="tcsh"/><category scheme="https://scripter.co/categories/find" term="find" label="find"/><category scheme="https://scripter.co/categories/escaping" term="escaping" label="escaping"/><category scheme="https://scripter.co/categories/regex" term="regex" label="regex"/></entry></feed>