<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Bash Scripting on Aamnah - Frontend Web Developer</title>
    <link>https://aamnah.com/notes/bash-scripting/</link>
    <description>Recent content in Bash Scripting on Aamnah - Frontend Web Developer</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 14 Apr 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://aamnah.com/notes/bash-scripting/rss.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Reading multiple lines of input from Bash terminal</title>
      <link>https://aamnah.com/notes/bash-scripting/read-readarray/</link>
      <pubDate>Fri, 29 Jul 2022 21:48:26 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/read-readarray/</guid>
      <description>&lt;p&gt;This came up when i was doing HackerRank challenges for Bash. The challenge called &lt;a href=&#34;https://www.hackerrank.com/challenges/bash-tutorials---compute-the-average/problem?isFullScreen=true&#34;&gt;Compute the Average&lt;/a&gt; had the following problem statement:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Given N integers, compute their average, rounded to three decimal places.&#xA;The first line contains an integer, N.&#xA;Each of the following N lines contains a single integer.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;My first attempt was to use &lt;code&gt;read&lt;/code&gt; with the &lt;code&gt;-r&lt;/code&gt; flag in a &lt;code&gt;while&lt;/code&gt; loop to read all lines one by one and ignore the &lt;code&gt;\&lt;/code&gt; character used to break up lines.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Practical examples of install scripts written in Bash</title>
      <link>https://aamnah.com/notes/bash-scripting/install-script-examples/</link>
      <pubDate>Sun, 30 May 2021 17:47:09 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/install-script-examples/</guid>
      <description>&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://get.docker.com/&#34;&gt;Docker&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://firebase.tools/&#34;&gt;Firebase CLI&lt;/a&gt; (has syntax highlighting too)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh&#34;&gt;Hombrew&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Append to a dconf list and avoiding duplicates with existing entries</title>
      <link>https://aamnah.com/notes/bash-scripting/dconf-append-list-avoid-duplicates/</link>
      <pubDate>Sun, 09 Aug 2020 20:05:39 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/dconf-append-list-avoid-duplicates/</guid>
      <description>&lt;p&gt;I need to do this for a script i&amp;rsquo;m writing to add custom keyboard shortcuts. I get the existing list with&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[&amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/&amp;#39;, &amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/&amp;#39;, &amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/&amp;#39;]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and now i need to add new entries to it and avoid duplicates with any previous &lt;code&gt;custom$&lt;/code&gt; shortcuts.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;gsettings &lt;span class=&#34;nb&#34;&gt;set&lt;/span&gt; org.gnome.settings-daemon.plugins.media-keys custom-keybindings &lt;span class=&#34;s2&#34;&gt;&amp;#34;[&amp;lt;altered_list&amp;gt;]&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;adding-values-to-an-existing-array&#34;&gt;Adding values to an existing array&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;arr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=(&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;arr&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[@]&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;new_element1&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;new_element2&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;...&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;new_elementN&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#Or&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;arr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;+=(&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;new_element1&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;new_element2&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;...&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;new_elementN&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;using-command-substituion&#34;&gt;using command substituion&lt;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;CUSTOM_SHORTCUTS_LIST&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;$(&lt;/span&gt;gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings&lt;span class=&#34;k&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# [&amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/&amp;#39;, &amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/&amp;#39;, &amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/&amp;#39;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; -e &lt;span class=&#34;s2&#34;&gt;&amp;#34;\nCUSTOM_SHORTCUTS_LIST: \n&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;CUSTOM_SHORTCUTS_LIST&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;NEW_SHORTCUTS_LIST&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;CUSTOM_SHORTCUTS_LIST&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;%]*&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;, &amp;#39;blah&amp;#39;]&amp;#34;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# substituion&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; -e &lt;span class=&#34;s2&#34;&gt;&amp;#34;\nNEW_SHORTCUTS_LIST: \n&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;NEW_SHORTCUTS_LIST&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;\n&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# [&amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/&amp;#39;, &amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/&amp;#39;, &amp;#39;/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/&amp;#39;, &amp;#39;blah&amp;#39;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here are some way people have done this when creating Gnome Terminal themes&lt;/p&gt;</description>
    </item>
    <item>
      <title>OSTYPE in Shell</title>
      <link>https://aamnah.com/notes/bash-scripting/ostype-shell/</link>
      <pubDate>Fri, 03 Jul 2020 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/ostype-shell/</guid>
      <description>&lt;h2 id=&#34;ostype&#34;&gt;OSTYPE&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;OSTYPE&lt;/code&gt; variable stores the value of the operating system type.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;$OSTYPE&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;linux-gnu # Ubuntu&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;zsh&lt;/code&gt; and &lt;code&gt;bash&lt;/code&gt; values differ a bit.&lt;/p&gt;&#xA;&lt;h3 id=&#34;bash&#34;&gt;bash&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ echo $OSTYPE&#xA;  darwin18&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;zsh&#34;&gt;zsh&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;% echo $OSTYPE&#xA;  darwin18.0&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use a glob to account for the inconsistency&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-conf&#34; data-lang=&#34;conf&#34;&gt;if [[ $OSTYPE == darwin* ]]; then&#xA;alias flushdns=&amp;#39;sudo dscacheutil -flushcache&amp;#39;&#xA;fi&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Another code snippet from the &lt;a href=&#34;http://software.virtualmin.com/gpl/scripts/install.sh&#34;&gt;virualmin install script&lt;/a&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;remove_virtualmin_release &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;# shellcheck disable=SC2154&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;case&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$os_type&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; in&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s2&#34;&gt;&amp;#34;fedora&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;centos&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;rhel&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;amazon&amp;#34;&lt;/span&gt;&#x9;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    run_ok &lt;span class=&#34;s2&#34;&gt;&amp;#34;rpm -e virtualmin-release&amp;#34;&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Removing virtualmin-release&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;;;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s2&#34;&gt;&amp;#34;debian&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;ubuntu&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    grep -v &lt;span class=&#34;s2&#34;&gt;&amp;#34;virtualmin&amp;#34;&lt;/span&gt; /etc/apt/sources.list &amp;gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$tempdir&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;/sources.list&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    mv &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$tempdir&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;/sources.list /etc/apt/sources.list&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;;;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;esac&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;uname--s&#34;&gt;uname -s&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;-s&lt;/code&gt; prints the kernel name&lt;/p&gt;</description>
    </item>
    <item>
      <title>Checking operating system in a bash script and installing different programs</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-script-check-operating-system-os-uname-ostype/</link>
      <pubDate>Sun, 28 Jun 2020 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-script-check-operating-system-os-uname-ostype/</guid>
      <description>&lt;p&gt;Because i have multiple machines and use both Ubuntu and macOS, I often need to alter my commands to account for differences in commands. For example, to get colorized output for the &lt;code&gt;ls&lt;/code&gt; command, Ubuntu would use the &lt;code&gt;--color&lt;/code&gt; flag while macOS will use the &lt;code&gt;-G&lt;/code&gt; flag. &lt;code&gt;-G&lt;/code&gt; in Ubuntu is for &lt;code&gt;--no-group&lt;/code&gt;, i.e. don&amp;rsquo;t print group names in long listing format. And i don&amp;rsquo;t want to write two different files for Ubuntu and macOS, i want to be able to use the same .dotfiles on both systems.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Batch rename filenames to snake_case</title>
      <link>https://aamnah.com/notes/bash-scripting/snake-case-bash/</link>
      <pubDate>Thu, 21 Mar 2019 08:02:11 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/snake-case-bash/</guid>
      <description>&lt;p&gt;tl;dr&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;sudo apt install rename&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;rename &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/ /_/g&amp;#39;&lt;/span&gt; *.&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;jpeg,jpg,png&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; rename &lt;span class=&#34;s1&#34;&gt;&amp;#39;y/A-Z/a-z/&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;ls &lt;span class=&#34;c1&#34;&gt;# get all filenames in the folder&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;ls *.&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;jpeg,jpg,png&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# get all .png, .jpg or .jpeg files&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{ print tolower($0) }&amp;#39;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# turn everything lowercase&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;sed &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/ /_/g&amp;#39;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# replace all spaces with underscores&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;ls *.&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;jpeg,jpg,png&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{ print tolower($0) }&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; sed &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/ /_/g&amp;#39;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# get all image filenames in snake_case in Terminal output&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;ls&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;#39;Army vet poor children.jpg&amp;#39;&#xA;&amp;#39;British Us Warships.jpg&amp;#39;&#xA;&amp;#39;First time loving a soldier Here’s the 101 you need .docx&amp;#39;&#xA;&amp;#39;Get in shape military way .docx&amp;#39;&#xA; LIVE&#xA;&amp;#39;Monday Motivation Posts_&amp;#39;&#xA;&amp;#39;Move over marvel, there’s a real Iron Man in town .docx&amp;#39;&#xA;&amp;#39;Prince Harry Green Caps.jpg&amp;#39;&#xA;&amp;#39;Prince Harry rewards Royal Marines with Green Berets as training ends  .docx&amp;#39;&#xA;&amp;#39;Recruitment taining 2019 things to keep in mind.jpg&amp;#39;&#xA;&amp;#39;Recruitment training 2019 things to keep in mind .docx&amp;#39;&#xA;&amp;#39;Titans comes together – US, British ships perform joint training.docx&amp;#39;&#xA;&amp;#39;Tornado goes out in style.docx&amp;#39;&#xA;&amp;#39;Tornado goes out in style.jpg&amp;#39;&#xA;&amp;#39;UK Defence Forces top the charts for LGBT empowerment .docx&amp;#39;&#xA;&amp;#39;UK defence forces LGBT top charts.jpg&amp;#39;&#xA;&amp;#39;Waste no excuse to tell your someone special how much you love them.png&amp;#39;&#xA;&amp;#39;Womens day.png&amp;#39;&#xA;&amp;#39;Writing the blues away.docx&amp;#39;&#xA;&amp;#39;Writing the blues away.jpg&amp;#39;&#xA;&amp;#39;amry vet runs for poor children .docx&amp;#39;&#xA; army_military_married_love_hand-74014.jpg&#xA; desktop.ini&#xA;&amp;#39;fitness army.jpg&amp;#39;&#xA; uploaded&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;ls *.&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;jpeg,jpg,png&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; awk &lt;span class=&#34;s1&#34;&gt;&amp;#39;{print tolower($0)}&amp;#39;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; sed &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/ /_/g&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ls: cannot access &amp;#39;*.jpeg&amp;#39;: No such file or directory&#xA;army_vet_poor_children.jpg&#xA;british_us_warships.jpg&#xA;prince_harry_green_caps.jpg&#xA;recruitment_taining_2019_things_to_keep_in_mind.jpg&#xA;tornado_goes_out_in_style.jpg&#xA;uk_defence_forces_lgbt_top_charts.jpg&#xA;waste_no_excuse_to_tell_your_someone_special_how_much_you_love_them.png&#xA;womens_day.png&#xA;writing_the_blues_away.jpg&#xA;army_military_married_love_hand-74014.jpg&#xA;fitness_army.jpg&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Loop it through and rename all image files..&lt;/p&gt;</description>
    </item>
    <item>
      <title>Write a Bash Function to Create a gruntfile.js for your project</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-function-create-gruntfile-js/</link>
      <pubDate>Fri, 13 Jul 2018 14:25:43 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-function-create-gruntfile-js/</guid>
      <description>&lt;h3 id=&#34;here-is-how-it-works&#34;&gt;Here is how it works&lt;/h3&gt;&#xA;&lt;p&gt;Everyt time i type &lt;code&gt;gruntfile&lt;/code&gt; in the Terminal, it creates a &lt;strong&gt;gruntfile.js&lt;/strong&gt; for me in the folder i am in. The resulting &lt;strong&gt;gruntfile.js&lt;/strong&gt; has the following template code:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-javascript&#34; data-lang=&#34;javascript&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nx&#34;&gt;module&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;exports&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kd&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;grunt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;grunt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;initConfig&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nx&#34;&gt;pkg&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;grunt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;file&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;readJSON&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;package.json&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;c1&#34;&gt;// CONFIG&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;p&#34;&gt;})&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// PLUGINS&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;grunt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;loadNpmTasks&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// TASKS&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;nx&#34;&gt;grunt&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;registerTask&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;default&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;13&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I can now add my Grunt config to it.&lt;/p&gt;&#xA;&lt;p&gt;What i have done is create a function &lt;code&gt;gruntfile&lt;/code&gt; for me and saved in my &lt;code&gt;.bash_profile&lt;/code&gt; so it is available to me anywhere in the Terminal.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Here Documents in Bash</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-here-docs/</link>
      <pubDate>Thu, 19 Apr 2018 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-here-docs/</guid>
      <description>&lt;h3 id=&#34;tldr&#34;&gt;tl;dr&lt;/h3&gt;&#xA;&lt;p&gt;a here document is special-purpose &lt;em&gt;code block&lt;/em&gt; that you can use to feed commands&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;ssh otherhost &lt;span class=&#34;s&#34;&gt;&amp;lt;&amp;lt; EOF&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s&#34;&gt;  ls some_folder; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s&#34;&gt;  ./someaction.sh &amp;#39;some params&amp;#39;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s&#34;&gt;  pwd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s&#34;&gt;  ./some_other_action &amp;#39;other params&amp;#39;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;s&#34;&gt;EOF&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;a &lt;strong&gt;limit string&lt;/strong&gt; (usually &lt;code&gt;EOF&lt;/code&gt;) indicates the start and finish of a here document. It doesn&amp;rsquo;t have to called &lt;code&gt;EOF&lt;/code&gt;, you can call it whatever, e.g. &lt;code&gt;JumanjiXYZ&lt;/code&gt; is a valid limit string&lt;/li&gt;&#xA;&lt;li&gt;Variables inside a Here document need to be quoted or else they won&amp;rsquo;t be substituted, like so: &lt;code&gt;&amp;quot;${VAR}&amp;quot;&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;The ending limit string needs to be at the beginning of the line&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;Here is an example where a here doc has been used to run multiple commands to the remote server. The script logs in to a remote server, takes a back up of all it&amp;rsquo;s databases and restores those databases directly on your current server, i.e. the server you ran the commands from&lt;/p&gt;</description>
    </item>
    <item>
      <title>Upgrade to Bash 4 on macOS</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-upgrade-3-4-macos/</link>
      <pubDate>Sun, 21 May 2017 00:00:01 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-upgrade-3-4-macos/</guid>
      <description>&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# install Homebrew&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# /usr/bin/ruby -e &amp;#34;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# install Bash via Homebrew&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;brew update &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; brew install bash&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Add the new shell to the list of allowed (white-listed) shells&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 8&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# sudo bash -c &amp;#39;echo /usr/local/bin/bash &amp;gt;&amp;gt; /etc/shells&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt; 9&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;$(&lt;/span&gt;brew --prefix&lt;span class=&#34;k&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;/bin/bash&amp;#34;&lt;/span&gt; &amp;gt;&amp;gt; /etc/shells&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;11&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Change to the new shell&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;chsh -s &lt;span class=&#34;k&#34;&gt;$(&lt;/span&gt;brew --prefix&lt;span class=&#34;k&#34;&gt;)&lt;/span&gt;/bin/bash &#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;sudo -i&lt;/code&gt; let&amp;rsquo;s you switch to &lt;code&gt;root&lt;/code&gt; user&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;brew --prefix&lt;/code&gt; gives you the location of Homebrew install directory (&lt;code&gt;/usr/local&lt;/code&gt; by default)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;cat /etc/shells&lt;/code&gt; gives you the list of allowed shells&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Associative Arrays in Bash</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-associative-arrays-iterate-loop/</link>
      <pubDate>Sun, 21 May 2017 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-associative-arrays-iterate-loop/</guid>
      <description>&lt;p&gt;Associative arrays are key/value pairs, like Objects in JavaScript. You can iterate/loop over them.&lt;/p&gt;&#xA;&lt;h3 id=&#34;create-declare-an-associative-array&#34;&gt;create (declare) an associative array&lt;/h3&gt;&#xA;&lt;p&gt;This is done with the &lt;code&gt;declare -A&lt;/code&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;declare&lt;/span&gt; -A foo &lt;span class=&#34;c1&#34;&gt;# declare an array&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;declare&lt;/span&gt; -A foo bar baz &lt;span class=&#34;c1&#34;&gt;# declare multiple arrays&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;declare&lt;/span&gt; -A &lt;span class=&#34;nv&#34;&gt;myArray&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=(&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;key1&lt;span class=&#34;o&#34;&gt;]=&lt;/span&gt;value1 &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;key2&lt;span class=&#34;o&#34;&gt;]=&lt;/span&gt;value2 &lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;key3&lt;span class=&#34;o&#34;&gt;]=&lt;/span&gt;value3 &lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# Initialise all at once&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;add-values-to-the-array&#34;&gt;add values to the array&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;foo&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;key&lt;span class=&#34;o&#34;&gt;]=&lt;/span&gt;value&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note the lack of spaces before and after the equal &lt;code&gt;=&lt;/code&gt; sign&lt;/p&gt;&#xA;&lt;h3 id=&#34;iterate-over-keyvalue-pairs&#34;&gt;iterate over key/value pairs&lt;/h3&gt;&#xA;&lt;p&gt;The keys are accessed using an exclamation point: &lt;code&gt;${!array[@]}&lt;/code&gt;, the values are accessed using &lt;code&gt;${array[@]}&lt;/code&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Directly run bash scripts in Github Gists locally in Terminal.</title>
      <link>https://aamnah.com/notes/bash-scripting/run-bash-scripts-gists-github-locally/</link>
      <pubDate>Mon, 13 Mar 2017 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/run-bash-scripts-gists-github-locally/</guid>
      <description>&lt;p&gt;This post is about running install scripts saved in Gists on Github locally from a Mac Terminal using curl. However, this should work for just about any script saved online and is not in any way limited to gists.&lt;/p&gt;&#xA;&lt;p&gt;You need to have &lt;strong&gt;Command Line Tools for Xcode&lt;/strong&gt; installed.&lt;/p&gt;&#xA;&lt;h2 id=&#34;run-a-script-off-a-github-gist&#34;&gt;Run a script off a Github Gist&lt;/h2&gt;&#xA;&lt;p&gt;First things first, find a script that you want to install. &lt;a href=&#34;https://gist.github.com/aamnah/aa48749844fffbd42633&#34;&gt;Here&lt;/a&gt; is a bash script that i wrote for installing WordPress.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Check if a program is installed</title>
      <link>https://aamnah.com/notes/bash-scripting/check-if-program-installed/</link>
      <pubDate>Mon, 30 Nov 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/check-if-program-installed/</guid>
      <description>&lt;p&gt;They key is in using &lt;code&gt;hash&lt;/code&gt; or &lt;code&gt;type&lt;/code&gt; to see if a command is available. For example, the output of&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;hash&lt;/span&gt; nano&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;will change based on whether &lt;code&gt;nano&lt;/code&gt; is installed or not. If nano is installed, you&amp;rsquo;ll get nothing. If &lt;code&gt;nano&lt;/code&gt; is &lt;em&gt;not&lt;/em&gt; installed, you&amp;rsquo;ll get an error.&lt;/p&gt;&#xA;&lt;p&gt;So, we check for an error to see if something is not installed.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;command&lt;/span&gt; -v foo &amp;gt;/dev/null 2&amp;gt;&lt;span class=&#34;p&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;||&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; &amp;gt;&lt;span class=&#34;p&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;I require foo but it&amp;#39;s not installed.  Aborting.&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;exit&lt;/span&gt; 1&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;OR&lt;/p&gt;</description>
    </item>
    <item>
      <title>Batch renaming files in Bash</title>
      <link>https://aamnah.com/notes/bash-scripting/batch-rename-files-bash/</link>
      <pubDate>Fri, 17 Apr 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/batch-rename-files-bash/</guid>
      <description>&lt;p&gt;Use &lt;code&gt;rename&lt;/code&gt;, which is a Perl script and maybe on your system already. You can use the rename command to quickly rename files using a regular expression pattern. For instance, if you wanted to rename all files containing foo to contain bar instead, you could use a command like this one:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;rename –v &lt;span class=&#34;s1&#34;&gt;&amp;#39;s/foo/bar/g&amp;#39;&lt;/span&gt; *    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;how-to-rename-multiple-files-based-on-a-pattern&#34;&gt;How to rename multiple files based on a pattern&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://stackoverflow.com/questions/15380205/rename-multiple-files-in-bash&#34;&gt;&lt;i class=&#34;fa fa-link&#34;&gt;&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; f in * &lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt; cp &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; 2014-08-26-&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;mv &lt;span class=&#34;nv&#34;&gt;$f&lt;/span&gt; &lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;f&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;#[0-9]*-&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Test&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to create a man page for your Bash Script</title>
      <link>https://aamnah.com/notes/bash-scripting/how-to-create-man-page-for-your-bash-script/</link>
      <pubDate>Sun, 22 Feb 2015 00:00:01 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/how-to-create-man-page-for-your-bash-script/</guid>
      <description>&lt;ul&gt;&#xA;&lt;li&gt;The man pages are written as &lt;code&gt;nroff&lt;/code&gt; files.&lt;/li&gt;&#xA;&lt;li&gt;The &lt;code&gt;/usr/local/man&lt;/code&gt; directory is the location typically used for any locally installed packages/files.&lt;/li&gt;&#xA;&lt;li&gt;You can look at examples by looking at the existing manpages, (which will likely need to be uncompressed first), also read man.&lt;/li&gt;&#xA;&lt;li&gt;Presently many users prefer &lt;code&gt;groff&lt;/code&gt; to &lt;code&gt;nroff&lt;/code&gt;, &lt;code&gt;man groff&lt;/code&gt; to get started&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;resources&#34;&gt;Resources&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;http://www.cyberciti.biz/faq/linux-unix-creating-a-manpage/&#34;&gt;Linux/UNIX Create a Manpage&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>How to take options for your Bash Script</title>
      <link>https://aamnah.com/notes/bash-scripting/how-to-take-options-arguments-for-your-bash-script/</link>
      <pubDate>Sun, 22 Feb 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/how-to-take-options-arguments-for-your-bash-script/</guid>
      <description>&lt;p&gt;Overview:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The distinction between &lt;em&gt;options&lt;/em&gt; (flags) and &lt;em&gt;positional args&lt;/em&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;getopts&lt;/code&gt; for short options, with &lt;code&gt;:&lt;/code&gt; meaning &amp;ldquo;takes a value&amp;rdquo; and &lt;code&gt;$OPTARG&lt;/code&gt; holding it&lt;/li&gt;&#xA;&lt;li&gt;Manual while/case loop for long options (GNU &lt;code&gt;getopt&lt;/code&gt; mentioned but not walked through)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;Options are the flags you pass to a script, like &lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;--verbose&lt;/code&gt;. Different from positional arguments (&lt;code&gt;$1&lt;/code&gt;, &lt;code&gt;$2&lt;/code&gt;, etc.) — options can come in any order, can be optional, and usually toggle behavior or carry a value.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bash script to create a new Jekyll post</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-script-to-create-new-jekyll-post/</link>
      <pubDate>Sat, 21 Feb 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-script-to-create-new-jekyll-post/</guid>
      <description>&lt;h2 id=&#34;getting-date&#34;&gt;Getting Date&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Date&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;DATE&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;date +%Y-%m-%d&lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will get today&amp;rsquo;s date in YYYY-MM-DD format.&lt;/p&gt;&#xA;&lt;h2 id=&#34;stripping-spaces-and-replacing-with-underscores&#34;&gt;Stripping spaces and replacing with underscores&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;$ &lt;span class=&#34;nv&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;This is just a test&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;$ &lt;span class=&#34;nb&#34;&gt;echo&lt;/span&gt; &lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;// /_&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;This_is_just_a_test&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;taking-it-further&#34;&gt;Taking it Further&lt;/h2&gt;&#xA;&lt;h3 id=&#34;make-it-a-function&#34;&gt;Make it a function&lt;/h3&gt;&#xA;&lt;p&gt;What&amp;rsquo;s cooler than a bash script? A bash function! With a function, we don&amp;rsquo;t have to specify script name/location every time. A bash function added to your &lt;code&gt;.bash_profile&lt;/code&gt; will work globally anywhere in the Terminal. The command to run would then become like this:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bash Scripts -  Load/Read/Include Settings from Another File</title>
      <link>https://aamnah.com/notes/bash-scripting/load-read-settings-from-another-file-bash-script/</link>
      <pubDate>Fri, 20 Feb 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/load-read-settings-from-another-file-bash-script/</guid>
      <description>&lt;p&gt;To include a script into another script, we use the &lt;code&gt;source&lt;/code&gt; command. In it&amp;rsquo;s simplest form, the command is this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;source&lt;/span&gt; incl.sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;rsquo;s an example. Our &lt;strong&gt;keys.cfg&lt;/strong&gt; file has this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;AWSAccessKeyId&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;AKIAIKRGQQKRGQQKRGQQ&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;AWSSecretKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;UNYDSEUNYDSEUNYDSEmwMeIdQ6KRGQQv7dBdzDSE&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;While our &lt;strong&gt;script.sh&lt;/strong&gt; has this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;cp&#34;&gt;#!/bin/bash &#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#Directory the script is in (for later use)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;SCRIPTDIR&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;$(&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;$(&lt;/span&gt; dirname &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;BASH_SOURCE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[0]&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;pwd&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Load the backup settings&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;7&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;source&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;${&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;SCRIPTDIR&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;/keys.cfg&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In our &lt;strong&gt;script.sh&lt;/strong&gt; file we have sourced the file &lt;strong&gt;keys.cfg&lt;/strong&gt; which contains configuration settings which we can now use.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Opencart Install Script</title>
      <link>https://aamnah.com/notes/bash-scripting/opencart-install-script-bash/</link>
      <pubDate>Tue, 17 Feb 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/opencart-install-script-bash/</guid>
      <description>&lt;p&gt;You can run this script directly using the following command&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;curl -L https://gist.githubusercontent.com/aamnah/93cb63fc15e708649084/raw &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; bash&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here is the code, add this to your &lt;strong&gt;~/.bash_profile&lt;/strong&gt; and it&amp;rsquo;ll be available for you anywhere in the terminal.&lt;/p&gt;&#xA;&lt;script src=&#34;https://gist.github.com/aamnah/93cb63fc15e708649084.js&#34;&gt;&lt;/script&gt;&#xA;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: To run just type &lt;code&gt;opencart&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;%7b%7bsite.url%7d%7dassets/img/bash-install-opencart-1.png&#34; alt=&#34;Install Opencart Screen 1&#34; loading=&#34;lazy&#34;&gt;&#xA;&lt;img src=&#34;%7b%7bsite.url%7d%7dassets/img/bash-install-opencart-2.png&#34; alt=&#34;Install Opencart Screen 2&#34; loading=&#34;lazy&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bash script to create OCMOD and vQmod templates with a single command</title>
      <link>https://aamnah.com/notes/bash-scripting/create-ocmod-vqmod-template-opencart-bash-script/</link>
      <pubDate>Mon, 16 Feb 2015 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/create-ocmod-vqmod-template-opencart-bash-script/</guid>
      <description>&lt;p&gt;OCMOD and vQmod are both modification systems for Opencart which allow you to change things without overwriting any core files. For Opencart version older than 2.x, vQmod was the king. With version 2.x Opencart launched it&amp;rsquo;s own modification system to replace the need for installing a separate extension.&lt;/p&gt;&#xA;&lt;p&gt;The state Opencart is in right now, you&amp;rsquo;ll find yourself dealing with both vqmod and ocmod scripts. I know i do. So i have written this neat bash script which allows me to type &lt;code&gt;ocmod foo&lt;/code&gt; to create a file called &lt;strong&gt;foo.ocmod.xml&lt;/strong&gt; with the basic template ocmod. Same for vqmod, type &lt;code&gt;vqmod bar&lt;/code&gt; and it&amp;rsquo;ll create a file called &lt;strong&gt;bar.xml&lt;/strong&gt; with vqmod tempalte code.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bash script to create Media Queries with Sass</title>
      <link>https://aamnah.com/notes/bash-scripting/bash-script-create-media-queries-sass/</link>
      <pubDate>Sat, 30 Aug 2014 00:00:00 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/bash-script-create-media-queries-sass/</guid>
      <description>&lt;p&gt;The following bash script will create a main sass stylesheet &lt;strong&gt;style.scss&lt;/strong&gt; and then create additional sass stylesheets for all devices (&lt;strong&gt;mobile.scss&lt;/strong&gt;, &lt;strong&gt;ipad.scss&lt;/strong&gt;, &lt;strong&gt;desktop.scss&lt;/strong&gt;, &lt;strong&gt;wide.scss&lt;/strong&gt;, &lt;strong&gt;iphone.scss&lt;/strong&gt;) in a folder called &lt;strong&gt;media-queries&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In the end, we will combine stylesheets for all devices into one by importing them into our main style.scss.&lt;/p&gt;&#xA;&lt;p&gt;I have divided the code for different devices in their own stylesheets becuase it keeps it is neat and organized and i prefer it that way. Sass does its magic and takes all the code from different files using &lt;code&gt;@import&lt;/code&gt; and gives me one neat stylesheet. In the HTML, i only need to link to one stylesheet, the one that Sass generated for me.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bash script to install a LAMP stack</title>
      <link>https://aamnah.com/notes/bash-scripting/script-bash-install-a-lamp-stack/</link>
      <pubDate>Thu, 05 Jun 2014 03:31:41 +0500</pubDate>
      <guid>https://aamnah.com/notes/bash-scripting/script-bash-install-a-lamp-stack/</guid>
      <description>&lt;p&gt;The following script installs Apache, MySQL and PHP as well as PHPMyAdmin and some tweaks. For Debian based systems including Ubuntu. To install, copy the script to the server and run in the same folder you copied the file to by running the command:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;ln&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;cl&#34;&gt;bash lamp.sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here is the script code:&lt;/p&gt;&#xA;&lt;script src=&#34;https://gist.github.com/aamnah/f03c266d715ed479eb46.js&#34;&gt;&lt;/script&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://gist.github.com/aamnah/f03c266d715ed479eb46&#34;&gt;View the Gist on Github&lt;/a&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
