<?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 Matus Stafura</title>
    <link>https://stafura.dev/tags/bash/</link>
    <description>Recent content in Bash on Matus Stafura</description>
    <generator>Hugo</generator>
    <language>en-US</language>
    <lastBuildDate>Sat, 25 Oct 2025 12:55:12 +0200</lastBuildDate>
    <atom:link href="https://stafura.dev/tags/bash/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Bash Script Testing with Bats: Complete Beginner&#39;s Guide</title>
      <link>https://stafura.dev/bash-script-testing-with-bats/</link>
      <pubDate>Sat, 25 Oct 2025 12:55:12 +0200</pubDate>
      <guid>https://stafura.dev/bash-script-testing-with-bats/</guid>
      <description>&lt;p&gt;One of the pillars of programming is testing the code. Most of the time, I wrote simple bash scripts without tests(bruh, but why waste time writing tests for couple of lines, right?).&lt;/p&gt;&#xA;&lt;p&gt;But recently I started developing a Go app with bash support, so it&amp;rsquo;s time to explore testing suites for bash.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;&#xA;&#xA;&lt;picture&gt;&#xA;    &#xA;      &#xA;&#xA;      &#xA;&#xA;      &#xA;      &#xA;&#xA;      &lt;source srcset=&#34;https://stafura.dev/images/blog/aa4xi5.webp&#34; type=&#34;image/webp&#34;&gt;&#xA;&#xA;    &#xA;&#xA;    &#xA;&#xA;    &lt;img&#xA;      src=&#34;https://stafura.dev/images/blog/aa4xi5.jpg&#34;&#xA;      alt=&#34;Bats Logo&#34;&#xA;      loading=&#34;lazy&#34;&#xA;      decoding=&#34;async&#34;&#xA;      width=&#34;623&#34;&#xA;      height=&#34;401&#34;&#xA;    /&gt;&#xA;&#xA;    &#xA;  &lt;/picture&gt;&#xA;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I found BATS (Bash Automated Testing System) and I think I don&amp;rsquo;t need to look further. It is simple to understand, with support for assertions, custom helpers, and more.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to encrypt and decrypt files with AES-256 with OpenSSL</title>
      <link>https://stafura.dev/how-to-encrypt-and-decrypt-files-with-aes-256-with-openssl/</link>
      <pubDate>Thu, 28 Nov 2024 00:00:00 +0000</pubDate>
      <guid>https://stafura.dev/how-to-encrypt-and-decrypt-files-with-aes-256-with-openssl/</guid>
      <description>&lt;p&gt;The worst nightmare is sending and storing sensitive or private data in plain text.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s improve that by encrypting the files with AES-256.&lt;/p&gt;&#xA;&lt;h2 id=&#34;install-openssl&#34;&gt;Install OpenSSL&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#282a36;-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:#6272a4&#34;&gt;# Let&amp;#39;s check if we have OpenSSL installed&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl version&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&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:#6272a4&#34;&gt;# If not, let&amp;#39;s install openssl&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sudo apt update &lt;span style=&#34;color:#ff79c6&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt install openssl -y&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;encrypt-file&#34;&gt;Encrypt File&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#282a36;-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:#6272a4&#34;&gt;# create a file with some content&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:#8be9fd;font-style:italic&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#f1fa8c&#34;&gt;&amp;#34;hello&amp;#34;&lt;/span&gt; &amp;gt; test.txt&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&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:#6272a4&#34;&gt;# Encrypt the file&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;openssl enc -aes-256-cbc -salt -pbkdf2 -iter &lt;span style=&#34;color:#bd93f9&#34;&gt;100000&lt;/span&gt; -in test.txt -out example.enc&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&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:#6272a4&#34;&gt;#### help ################################################################&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:#6272a4&#34;&gt;# -salt     - Ensures that the same plaintext encrypted multiple &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:#6272a4&#34;&gt;#             times with the same key produces different ciphertexts&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:#6272a4&#34;&gt;# -pbkdf2   - Password-Based Key Derivation Function 2 &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:#6272a4&#34;&gt;#             algorithm used to derive the encryption key from a password&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:#6272a4&#34;&gt;# -iter     - Specifies the number of iterations for the algorithm&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:#6272a4&#34;&gt;##########################################################################&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&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:#6272a4&#34;&gt;# check if we have encrypted file&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ls&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6272a4&#34;&gt;# test.txt example.enc&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&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:#6272a4&#34;&gt;# let&amp;#39;s see the contents of encrypted file&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;cat example.enc&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6272a4&#34;&gt;# Salted__�!ei��/�+�΀O��l3%&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Yay, no one can read that.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
