<?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 Backend Engineering Strategy Tools</title><link>https://backend-engineering-strategy-tools.github.io/site/tags/bash/</link><description>Recent content in Bash on Backend Engineering Strategy Tools</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 01 Jan 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://backend-engineering-strategy-tools.github.io/site/tags/bash/index.xml" rel="self" type="application/rss+xml"/><item><title>Bash</title><link>https://backend-engineering-strategy-tools.github.io/site/public-notes/languages/bash/</link><pubDate>Mon, 01 Jan 2024 00:00:00 +0000</pubDate><guid>https://backend-engineering-strategy-tools.github.io/site/public-notes/languages/bash/</guid><description>&lt;p&gt;Bash is unavoidable in DevOps work — CI/CD pipelines, container entrypoints, system init scripts, and quick automation all end up as shell scripts eventually. Knowing how to write it well saves a lot of pain.&lt;/p&gt;
&lt;h2 id="tooling"&gt;Tooling
&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Linting:&lt;/strong&gt; &lt;a class="link" href="https://www.shellcheck.net/" target="_blank" rel="noopener"
 &gt;ShellCheck&lt;/a&gt;: catches common mistakes and anti-patterns. Run it in CI, or install the IDE plugin. Most of what it flags is genuinely wrong.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IDE:&lt;/strong&gt; Any editor works. ShellCheck integrations exist for VS Code, IntelliJ, Vim, and most others.&lt;/p&gt;
&lt;h2 id="good-habits"&gt;Good habits
&lt;/h2&gt;&lt;p&gt;Set these at the top of every non-trivial script:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#!/usr/bin/env bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;set -euo pipefail
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-e&lt;/code&gt; — exit on error&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-u&lt;/code&gt; — error on unset variables&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-o pipefail&lt;/code&gt;: catch errors in pipes, not just the last command&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Use &lt;code&gt;shellcheck&lt;/code&gt; before committing. Most Bash bugs it catches are subtle and only surface under specific conditions in production.&lt;/p&gt;
&lt;h2 id="when-to-reach-for-python-instead"&gt;When to reach for Python instead
&lt;/h2&gt;&lt;p&gt;When the script grows beyond ~50 lines, needs associative arrays, JSON parsing, or HTTP calls — switch to Python. Bash is great glue; it&amp;rsquo;s a poor application language.&lt;/p&gt;
&lt;h2 id="resources"&gt;Resources
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://www.shellcheck.net/" target="_blank" rel="noopener"
 &gt;ShellCheck&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://www.gnu.org/software/bash/manual/" target="_blank" rel="noopener"
 &gt;Bash Reference Manual&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://google.github.io/styleguide/shellguide.html" target="_blank" rel="noopener"
 &gt;Google Shell Style Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>