<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bash on Samarthya</title><link>https://samarthya.me/tags/bash/</link><description>Recent content in Bash on Samarthya</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© Samarthya 2018-2026. All rights reserved.</copyright><lastBuildDate>Thu, 02 Feb 2023 12:00:00 +0000</lastBuildDate><atom:link href="https://samarthya.me/tags/bash/index.xml" rel="self" type="application/rss+xml"/><item><title>Python vs Bash</title><link>https://samarthya.me/posts/python-vs-bash/</link><pubDate>Thu, 02 Feb 2023 12:00:00 +0000</pubDate><guid>https://samarthya.me/posts/python-vs-bash/</guid><description>&lt;figure&gt;&lt;img&#10; class="my-0 rounded-md"&#10; loading="lazy"&#10; decoding="async"&#10; fetchpriority="auto"&#10; alt="Python compared with Bash: kind of language, what each is best for, libraries, and when to choose each"&#10; width="1200"&#10; height="630"&#10; src="https://samarthya.me/posts/python-vs-bash/pycomp_hu_9aa880e447e5b1c6.png"&#10; srcset="https://samarthya.me/posts/python-vs-bash/pycomp_hu_9aa880e447e5b1c6.png 800w, https://samarthya.me/posts/python-vs-bash/pycomp.png 1280w"&#10; sizes="(min-width: 768px) 50vw, 65vw"&#10; data-zoom-src="https://samarthya.me/posts/python-vs-bash/pycomp.png"&gt;&lt;figcaption&gt;Recreated in October 2026 from the post; the original image was lost&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p&gt;Python and bash are both programming languages, but they have different purposes and use cases.&lt;/p&gt;</description></item><item><title>Bash: Named Reference</title><link>https://samarthya.me/posts/bash-named-reference/</link><pubDate>Wed, 02 Mar 2022 12:00:00 +0000</pubDate><guid>https://samarthya.me/posts/bash-named-reference/</guid><description>&lt;p&gt;Bash is different world. Powerful, simple, elegant and complex all at the same time. Recently while trying to reduce the burden of repetitive code, I was trying to check what can be done to use references in Bash (something like pointers) and it was an interesting problem that I enjoyed solving.&lt;/p&gt;</description></item><item><title>Notes: For self</title><link>https://samarthya.me/posts/notes-1/</link><pubDate>Wed, 23 Feb 2022 07:27:42 +0000</pubDate><guid>https://samarthya.me/posts/notes-1/</guid><description>&lt;div&#10; class="tab__container w-full"&#10; &#10; &gt;&#10; &lt;div class="tab__nav" role="tablist"&gt;&#10; &lt;div class="flex flex-wrap gap-1"&gt;&lt;button&#10; class="tab__button px-3 py-2 text-sm font-semibold border-b-2 border-transparent rounded-t-md hover:bg-neutral-200 dark:hover:bg-neutral-700 tab--active"&#10; role="tab"&#10; aria-selected="true"&#10; data-tab-index="0"&#10; data-tab-label="bash"&gt;&#10; &lt;span class="flex items-center gap-1"&gt;&#10; &#10; bash&#10; &lt;/span&gt;&#10; &lt;/button&gt;&lt;button&#10; class="tab__button px-3 py-2 text-sm font-semibold border-b-2 border-transparent rounded-t-md hover:bg-neutral-200 dark:hover:bg-neutral-700 "&#10; role="tab"&#10; aria-selected="false"&#10; data-tab-index="1"&#10; data-tab-label="= &amp;amp; =="&gt;&#10; &lt;span class="flex items-center gap-1"&gt;&#10; &#10; = &amp;amp; ==&#10; &lt;/span&gt;&#10; &lt;/button&gt;&lt;button&#10; class="tab__button px-3 py-2 text-sm font-semibold border-b-2 border-transparent rounded-t-md hover:bg-neutral-200 dark:hover:bg-neutral-700 "&#10; role="tab"&#10; aria-selected="false"&#10; data-tab-index="2"&#10; data-tab-label="Brackets ["&gt;&#10; &lt;span class="flex items-center gap-1"&gt;&#10; &#10; Brackets [&#10; &lt;/span&gt;&#10; &lt;/button&gt;&lt;button&#10; class="tab__button px-3 py-2 text-sm font-semibold border-b-2 border-transparent rounded-t-md hover:bg-neutral-200 dark:hover:bg-neutral-700 "&#10; role="tab"&#10; aria-selected="false"&#10; data-tab-index="3"&#10; data-tab-label="bc"&gt;&#10; &lt;span class="flex items-center gap-1"&gt;&#10; &#10; bc&#10; &lt;/span&gt;&#10; &lt;/button&gt;&lt;button&#10; class="tab__button px-3 py-2 text-sm font-semibold border-b-2 border-transparent rounded-t-md hover:bg-neutral-200 dark:hover:bg-neutral-700 "&#10; role="tab"&#10; aria-selected="false"&#10; data-tab-index="4"&#10; data-tab-label="awk"&gt;&#10; &lt;span class="flex items-center gap-1"&gt;&#10; &#10; awk&#10; &lt;/span&gt;&#10; &lt;/button&gt;&lt;/div&gt;&#10; &lt;/div&gt;&#10; &lt;div class="tab__content mt-4"&gt;&lt;div class="tab__panel tab--active" data-tab-index="0"&gt;&#10; &lt;ul&gt;&#10;&lt;li&gt;Bash is a string oriented language&lt;/li&gt;&#10;&lt;li&gt;We do not write &lt;code&gt;step=$((step++))&lt;/code&gt; this expression will return a numeric value which the shell will then take as the command to to be executed.&lt;/li&gt;&#10;&lt;li&gt;No spaces are allowed around the equal sign for variable assignment.&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;let &amp;quot;step++&amp;quot;&lt;/code&gt; is same as &lt;code&gt;(( step++ ))&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;Use &lt;code&gt;declare&lt;/code&gt; to set variable values and attributes&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&#10; &lt;/div&gt;&lt;div class="tab__panel " data-tab-index="1"&gt;&#10; In bash &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;==&lt;/code&gt; both mean the same thing&#10; &lt;/div&gt;&lt;div class="tab__panel " data-tab-index="2"&gt;&#10; &lt;blockquote&gt;&lt;p&gt;💬 What is the difference between &lt;code&gt;[&lt;/code&gt; and &lt;code&gt;[[&lt;/code&gt;?&lt;/p&gt;&#10;&lt;/blockquote&gt;&lt;ol class="not-prose my-10 space-y-5 border-s border-primary-200 ps-6 dark:border-primary-900"&gt;&#10;&lt;li class="relative"&gt;&#10; &lt;span class="absolute -start-10 top-0 flex h-8 w-8 items-center justify-center rounded-full bg-primary-600 text-sm font-black text-white ring-4 ring-neutral dark:ring-neutral-800"&gt;•&lt;/span&gt;&#10; &lt;h3 class="text-lg font-bold text-neutral-900 dark:text-white"&gt;if cd $dir; then&lt;/h3&gt;&#10; &lt;div class="mt-1 text-neutral-600 dark:text-neutral-400"&gt;&lt;p&gt;In this case the command &lt;code&gt;cd $dir&lt;/code&gt; will be executed and based on success or failure of the command executed the if or else part will be executed respectively.&lt;/p&gt;&#10;&lt;h3 class="relative group"&gt;&lt;code&gt;if [$dir]; then&lt;/code&gt;&#10; &lt;div id="if-dir-then" class="anchor"&gt;&lt;/div&gt;&#10;&lt;pre&gt;&lt;code&gt;&amp;lt;span&#10; class=&amp;quot;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none&amp;quot;&amp;gt;&#10; &amp;lt;a class=&amp;quot;text-primary-300 dark:text-neutral-700 !no-underline&amp;quot; href=&amp;quot;#if-dir-then&amp;quot; aria-label=&amp;quot;Anchor&amp;quot;&amp;gt;#&amp;lt;/a&amp;gt;&#10;&amp;lt;/span&amp;gt;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/h3&gt;&#10;&lt;p&gt;Single bracket is equivalent to test command evaluate conditional expression&lt;/p&gt;&#10;&lt;ol class="not-prose my-10 space-y-5 border-s border-primary-200 ps-6 dark:border-primary-900"&gt;&#10;&lt;li class="relative"&gt;&#10; &lt;span class="absolute -start-10 top-0 flex h-8 w-8 items-center justify-center rounded-full bg-primary-600 text-sm font-black text-white ring-4 ring-neutral dark:ring-neutral-800"&gt;•&lt;/span&gt;&#10; &lt;h3 class="text-lg font-bold text-neutral-900 dark:text-white"&gt;&amp;lt; &amp;amp; &amp;gt;&lt;/h3&gt;&#10; &lt;div class="mt-1 text-neutral-600 dark:text-neutral-400"&gt;&lt;ul&gt;&#10;&lt;li&gt;Within &lt;code&gt;[&lt;/code&gt; compare using simple ASCII ordering &amp;amp; within &lt;code&gt;[[&lt;/code&gt; comparison is lexicographic.&lt;/li&gt;&#10;&lt;li&gt;Within &lt;code&gt;[&lt;/code&gt; you have to escape &lt;code&gt;\&amp;gt;&lt;/code&gt; to avoid redirection.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/div&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;&#10; &lt;/div&gt;&lt;div class="tab__panel " data-tab-index="3"&gt;&#10; &lt;blockquote&gt;&lt;p&gt;💬 BC is a language?&lt;/p&gt;&#10;&lt;/blockquote&gt;&lt;div&#10; id="accordion-8263b81ba10c2527e53c5b24ef678386"&#10; class="border border-neutral-200 dark:border-neutral-700 rounded-lg overflow-hidden"&#10; data-accordion="collapse"&#10; data-accordion-separated="false"&#10;&gt;&#10;&lt;details&#10; class="group border-none"&#10; data-accordion-item&#10;&lt;blockquote&gt;&lt;/blockquote&gt; &lt;summary class="flex w-full cursor-pointer items-center justify-between gap-4 px-4 py-3 text-left text-lg font-semibold text-neutral-900 dark:text-neutral-100"&gt;&#10; &lt;span class="flex items-center gap-2"&gt;&#10;&lt;pre&gt;&lt;code&gt; &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;&#10;&amp;lt;/span&amp;gt;&#10;&amp;lt;span class=&amp;quot;accordion-chevron ms-auto flex h-5 w-5 items-center justify-center print:hidden&amp;quot;&amp;gt;&#10; &amp;lt;span class=&amp;quot;relative block icon&amp;quot;&amp;gt;&amp;lt;svg&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;p&gt;xmlns=&amp;ldquo;&lt;a href="http://www.w3.org/2000/svg%22" target="_blank" rel="noreferrer"&gt;http://www.w3.org/2000/svg"&lt;/a&gt;&#10;viewBox=&amp;ldquo;0 0 20 20&amp;rdquo;&#10;fill=&amp;ldquo;currentColor&amp;rdquo;&#10;aria-hidden=&amp;ldquo;true&amp;rdquo;&lt;/p&gt;&#10;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;path&#10;fill-rule="evenodd"&#10;d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z"&#10;clip-rule="evenodd"&#10;/&gt;&#10;&lt;/svg&gt;&#10;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/p&gt;&#10; &lt;/summary&gt;&#10;&lt;div class="px-4 pb-4 text-neutral-700 dark:text-neutral-300"&gt;&#10; &lt;/div&gt;&#10;&lt;/details&gt;&#10;&lt;/div&gt;&#10;&lt;style&gt;&#10; #accordion-8263b81ba10c2527e53c5b24ef678386 &gt; details + details {&#10; border-top: 1px solid rgb(var(--color-neutral-200));&#10; }&#10; .dark #accordion-8263b81ba10c2527e53c5b24ef678386 &gt; details + details {&#10; border-top-color: rgb(var(--color-neutral-700));&#10; }&#10;&lt;/style&gt;&#10;&lt;style&gt;&#10; #accordion-8263b81ba10c2527e53c5b24ef678386 details[data-accordion-item] &gt; summary .accordion-chevron {&#10; transform: rotate(-90deg);&#10; transition: transform 200ms ease-in-out;&#10; }&#10; #accordion-8263b81ba10c2527e53c5b24ef678386 details[data-accordion-item][open] &gt; summary .accordion-chevron {&#10; transform: rotate(0deg);&#10; }&#10;&lt;/style&gt;&#10;&lt;script&gt;&#10; (() =&gt; {&#10; const root = document.getElementById("accordion-8263b81ba10c2527e53c5b24ef678386");&#10; if (!root) return;&#10; const items = root.querySelectorAll("details[data-accordion-item]");&#10; items.forEach((item) =&gt; {&#10; item.addEventListener("toggle", () =&gt; {&#10; if (!item.open) return;&#10; items.forEach((other) =&gt; {&#10; if (other !== item) other.removeAttribute("open");&#10; });&#10; });&#10; });&#10; })();&#10;&lt;/script&gt;&#10;&lt;blockquote&gt;&lt;p&gt;💬 Supports arbitrary precision numbers with interactive execution of statements. (Command line)&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10; &lt;/div&gt;&lt;div class="tab__panel " data-tab-index="4"&gt;&#10; &lt;p&gt;&lt;code&gt;awk&lt;/code&gt; provides filtering capabilities&lt;/p&gt;&#10;&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&amp;gt; printf &amp;#39;gate\napple\nwhat\nkite\n&amp;#39; | awk &amp;#39;/at/&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;gate&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;what&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;printf &amp;#39;gate\napple\nwhat\nkite\n&amp;#39; | awk &amp;#39;!/e/&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;what&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&#10;&lt;p&gt;&lt;code&gt;awk&lt;/code&gt; is primarily used for field based processing&lt;/p&gt;&#10;&lt;p&gt;One liner structure &lt;code&gt;awk 'cond1{action1} cond2{action2} … condN{actionN}'&lt;/code&gt;&lt;/p&gt;&#10;&#10; &lt;/div&gt;&lt;/div&gt;&#10;&lt;/div&gt;</description></item></channel></rss>