<?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">alias on A Scripter's Notes</title><subtitle type="html">Emacs, scripting and anything text oriented.</subtitle><link href="https://scripter.co/categories/alias/" rel="alternate" type="text/html" title="HTML"/><link href="https://scripter.co/categories/alias/index.xml" rel="alternate" type="application/rss+xml" title="RSS"/><link href="https://scripter.co/categories/alias/atom.xml" rel="self" type="application/atom+xml" title="Atom"/><link href="https://scripter.co/categories/alias/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/alias/</id><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></feed>