<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="/rss.xsl"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Bash on Raveen Kumar</title>
    <link>https://raveenkumar.com/tags/bash/</link>
    <description>Recent content in Bash on Raveen Kumar</description>
    <generator>Hugo</generator>
    <language>en-US</language>
    <copyright>Raveen Kumar</copyright>
    <lastBuildDate>Fri, 12 May 2023 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://raveenkumar.com/tags/bash/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>fc fix command or fix previous command</title>
      <link>https://raveenkumar.com/posts/2023-05-12-fc-fix-command-or-fix-previous-command/</link>
      <pubDate>Fri, 12 May 2023 00:00:00 +0000</pubDate>
      <guid>https://raveenkumar.com/posts/2023-05-12-fc-fix-command-or-fix-previous-command/</guid>
      <description>&lt;p&gt;In Bash, &lt;code&gt;fc&lt;/code&gt; stands for &amp;ldquo;fix command&amp;rdquo; and it is a built-in command that allows you to work with the command history. The &lt;code&gt;fc&lt;/code&gt; command provides a way to view, edit, and re-execute commands from your command history.&lt;/p&gt;&#xA;&lt;p&gt;Here are some common uses of the &lt;code&gt;fc&lt;/code&gt; command:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;Viewing command history&lt;/strong&gt;: You can use &lt;code&gt;fc -l&lt;/code&gt; or simply &lt;code&gt;fc&lt;/code&gt; to display the list of recently executed commands. By default, it shows the most recent commands with line numbers.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Bash</title>
      <link>https://raveenkumar.com/library/programming/bash/</link>
      <pubDate>Thu, 16 Feb 2023 00:00:00 +0000</pubDate>
      <guid>https://raveenkumar.com/library/programming/bash/</guid>
      <description>&lt;h2 id=&#34;bash&#34;&gt;Bash&lt;/h2&gt;&#xA;&lt;h2 id=&#34;reading-materials&#34;&gt;Reading materials&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://blog.yossarian.net/2020/01/23/Anybody-can-write-good-bash-with-a-little-effort&#34;&gt;https://blog.yossarian.net/2020/01/23/Anybody-can-write-good-bash-with-a-little-effort&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://will-keleher.com/posts/5-Useful-Bash-Patterns.html&#34;&gt;https://will-keleher.com/posts/5-Useful-Bash-Patterns.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://timvisee.com/blog/elegant-bash-conditionals&#34;&gt;https://timvisee.com/blog/elegant-bash-conditionals&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://srobb.net/shellscripting.html&#34;&gt;https://srobb.net/shellscripting.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://srobb.net/bashtips.html&#34;&gt;https://srobb.net/bashtips.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;select-statement&#34;&gt;Select statement&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;select&lt;/span&gt; opt in y n; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;echo $opt&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This creates a loop where the user can select the option. Use case to break out of the loop.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;select&lt;/span&gt; opt in y n; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;echo $opt selected&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; $opt in&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;y&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;break &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;n&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;break &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;*&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;echo wrong option&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;esac&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;bash-variables&#34;&gt;Bash variables&lt;/h2&gt;&#xA;&lt;pre&gt;&lt;code&gt;$USER&#xA;$HOSTNAME&#xA;$PS1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;h3 id=&#34;to-find-or-list-all-environment-variables&#34;&gt;To Find or List all environment variables&lt;/h3&gt;&#xA;&lt;pre&gt;&lt;code&gt;env&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is useful when we want to manage the shell variables properly&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to customize tmux status bar with shell scripts</title>
      <link>https://raveenkumar.com/posts/2022-10-06-customize-tmux-status-bar-with-shell-scripts/</link>
      <pubDate>Thu, 06 Oct 2022 00:00:00 +0000</pubDate>
      <guid>https://raveenkumar.com/posts/2022-10-06-customize-tmux-status-bar-with-shell-scripts/</guid>
      <description>&lt;p&gt;TMUX status bar can be customized to run shell scripts.&lt;/p&gt;&#xA;&lt;p&gt;In the &lt;code&gt;.tmux.conf&lt;/code&gt; file, in the status left or right command execute the shell script using the following syntax,&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;set -g status-right &#39;| #(shell_script.bash) |&#39;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This will print the output of that shell script in the status bar. Useful if you want to check the size the home directory.&lt;/p&gt;&#xA;&lt;p&gt;Contents of &lt;code&gt;shell_script.bash&lt;/code&gt; example&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#!/bin/bash&#xA;&#xA;df -h $HOME | awk &#39;{print $5}&#39; | tail -n 1&#xA;&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    <item>
      <title>How to change hostname</title>
      <link>https://raveenkumar.com/posts/2022-09-13-change-hostname/</link>
      <pubDate>Tue, 13 Sep 2022 00:00:00 +0000</pubDate>
      <guid>https://raveenkumar.com/posts/2022-09-13-change-hostname/</guid>
      <description>&lt;h2 id=&#34;how-to-change-hostname&#34;&gt;How to change hostname&lt;/h2&gt;&#xA;&lt;h2 id=&#34;print-hostname&#34;&gt;Print hostname&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;hostname&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;hostname -I&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;echo $HOSTNAME&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;to-change-hostname&#34;&gt;To change hostname&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sudo hostname -b &amp;lt;New name&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sudo echo &amp;lt;new name&amp;gt; /etc/hostname&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#xA;&lt;li&gt;change name in &lt;code&gt;/etc/hosts&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;If you are in wsl, add the following entry to &lt;code&gt;/etc/wsl.conf&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-config&#34; data-lang=&#34;config&#34;&gt;[network]&#xA;generateHosts = false&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&#xA;&lt;li&gt;Restart computer&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>How to kill subprocess of a shell</title>
      <link>https://raveenkumar.com/posts/2022-02-08-kill-subprocess-of-a-shell/</link>
      <pubDate>Tue, 08 Feb 2022 00:00:00 +0000</pubDate>
      <guid>https://raveenkumar.com/posts/2022-02-08-kill-subprocess-of-a-shell/</guid>
      <description>&lt;h2 id=&#34;how-to-kill-subprocesses-of-a-shell&#34;&gt;How to kill subprocesses of a shell&lt;/h2&gt;&#xA;&lt;p&gt;In bash &lt;code&gt;$$&lt;/code&gt; will get you current process id.&lt;/p&gt;&#xA;&lt;p&gt;You can use &lt;code&gt;pkill -P $$&lt;/code&gt; to kill all subprocess of the current shell.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   -P, --parent ppid,...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          Only match processes whose parent process ID is listed.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&#34;https://stackoverflow.com/questions/2618403/how-to-kill-all-subprocesses-of-shell#:~:text=pkill%20%2DP%20%24%24,of%20the%20script%20itself&#34;&gt;Stackoverflow answer&lt;/a&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
