<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel><title>bugs | Hugo Ferreira</title>
    <link>https://hugo.ferreira.cc/tags/bugs/</link>
    <description>Recent content in Bugs by Hugo Ferreira</description>
    <image>
      <title>bugs | Hugo Ferreira</title>
      <url>https://hugo.ferreira.cc/hf-bw.jpg</url>
      <link>https://hugo.ferreira.cc/tags/bugs/</link>
    </image>
    <generator>Hugo -- 0.124.1</generator>
    <language>en</language>
    <copyright>2000–2024 by Hugo Ferreira · CC BY 4.0</copyright>
    <lastBuildDate>Wed, 29 May 2024 11:15:37 +0000</lastBuildDate>
    <atom:link href="https://hugo.ferreira.cc/tags/bugs/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>🔗 azet/community_bash_style_guide</title>
      <link>https://hugo.ferreira.cc/bash-style-guide/</link>
      <pubDate>Wed, 29 May 2024 11:15:37 +0000</pubDate>
      <guid>https://hugo.ferreira.cc/bash-style-guide/</guid>
      <description>GitHub - azet/community_bash_style_guide: Community Bash Style Guide: writing useful and modern bash scripts, seriously.
When to use bash and when to avoid bash
it&amp;rsquo;s rather simple:
does it need to glue userland utilities together? use bash. does it need to do complex tasks (e.g. database queries)? use something else. Why? … It consumes a lot of time and is often very difficult to debug in comparison to dynamic programming languages such as python, ruby or even perl.</description>
      <content:encoded><![CDATA[<p><a href="https://github.com/azet/community_bash_style_guide">GitHub - azet/community_bash_style_guide: Community Bash Style Guide: writing useful and modern bash scripts, seriously.</a></p>
<blockquote>
<p><strong>When to use bash and when to avoid bash</strong></p>
<p>it&rsquo;s rather simple:</p>
<ul>
<li>does it need to glue userland utilities together? use bash.</li>
<li>does it need to do complex tasks (e.g. database queries)? use something else.</li>
</ul>
<p>Why? … It consumes a lot of time and is often very difficult to debug in comparison to dynamic programming languages such as python, ruby or even perl. You are simply going to waste valuable time, performance and nerve you could have spent better otherwise.</p>
</blockquote>
<hr>
<blockquote>
<p><strong>Style conventions</strong></p>
<p>…</p>
<ul>
<li>Thus, scripts should somewhat reflect the following general layout:</li>
</ul>
<pre tabindex="0"><code>#!/usr/bin/env bash
#
# AUTHORS, LICENSE and DOCUMENTATION
#
set -eu -o pipefail

Readonly Variables
Global Variables

Import (&#34;source scriptname&#34;) of external source code 

Functions
…

Main
…
</code></pre></blockquote>
<hr>
<blockquote>
<p><strong>Use built in variable expansion instead of sed/awk</strong></p>
<p>…</p>
<p>same thing with string replacement.</p>
<pre tabindex="0"><code># ${VAR/PATTERN/STRING} # single replacement
# ${VAR//PATTERN/STRING} # all match replacement
# Use ${VAR#PATTERN} ${VAR%PATTERN} ${VAR/PATTERN} for string removal

VAR=foofoobar
${VAR/foo/bar} # barfoobar
${VAR//foo/bar} # barbarbar
${VAR//foo} # bar
</code></pre><p>More examples and uses here: <a href="http://wiki.bash-hackers.org/syntax/pe">http://wiki.bash-hackers.org/syntax/pe</a> <em>(<a href="https://web.archive.org/web/20230408142504/https://wiki.bash-hackers.org/syntax/pe">Internet Archive 2023-04-08</a>)</em></p>
</blockquote>
]]></content:encoded>
    </item>
  </channel>
</rss>
