<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Colas.Nahaboo.net - bash</title>
    <subtitle>Colas Nahaboo personal site, with discussions about programming code, web and computing topics, surfing and SUPing, and various musings.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://colas.nahaboo.net/tags/bash/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://colas.nahaboo.net"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-03-26T00:00:00+00:00</updated>
    <id>https://colas.nahaboo.net/tags/bash/atom.xml</id>
    <entry xml:lang="en">
        <title>Foswiki update script</title>
        <published>2026-03-26T00:00:00+00:00</published>
        <updated>2026-03-26T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://colas.nahaboo.net/code/foswiki-update-script/"/>
        <id>https://colas.nahaboo.net/code/foswiki-update-script/</id>
        
        <content type="html" xml:base="https://colas.nahaboo.net/code/foswiki-update-script/">&lt;p&gt;Although I have &lt;a href=&quot;&#x2F;blog&#x2F;a-new-version-of-the-site-for-2026-in-zola&quot;&gt;migrated my public site to zola&lt;&#x2F;a&gt; which was on &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foswiki.org&quot;&gt;Foswiki&lt;&#x2F;a&gt;, I have decided for now to keep my private family wiki on Foswiki for now.&lt;&#x2F;p&gt;
&lt;p&gt;So I needed to upgrade it to 2.1.11, it was still in 2.1.6, and since the upgrade is not exactly intuitive, I made a bash script to automatise the upgrade.&lt;&#x2F;p&gt;
&lt;p&gt;You can find it &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ColasNahaboo&#x2F;foswiki-upgrade&quot;&gt;on GitHub&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;See also its publication on the Foswiki site, with a &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;foswiki.org&#x2F;Support&#x2F;BestPracticeTip35#comment1.1774606339&quot;&gt;reminder of the standard upgrade method&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-the-script-works&quot;&gt;How the Script Works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-the-script-works&quot; aria-label=&quot;Anchor link for: how-the-script-works&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;This script supposes a modern version of Foswiki (v2+): it blindly overwrites the files that should not have been modified, so when customizing your wiki be sure to never directly modify distributed files.&lt;&#x2F;p&gt;
&lt;p&gt;The script however will not overwrite blindly any topic file that has been edited via Foswiki itself, by checking the author metadata. It will perform a 3-way merge, as automated as possible.&lt;&#x2F;p&gt;
&lt;p&gt;It also works only on a local copy of the site. You will have to download yourself a copy of your site, upgrade, and then re-upload it in place. This keeps the script simpler and safer.&lt;&#x2F;p&gt;
&lt;p&gt;It works on linux, but should work in linux-like layers on top of other OSes, such as cygwin, WSL, Homebrew, ...&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why-staying-on-foswiki&quot;&gt;Why staying on Foswiki?&lt;a class=&quot;zola-anchor&quot; href=&quot;#why-staying-on-foswiki&quot; aria-label=&quot;Anchor link for: why-staying-on-foswiki&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;My private wiki is used by me, but also my wife, who is not really fluent in wiki or markdown  editing, so an excellent WYSIWYG is a must. And personnaly, I hate databases and strive for stability and simple architecture. Foswiki has all these qualities... and I would have a lot of content to convert.&lt;&#x2F;p&gt;
&lt;p&gt;But I will probably switch to an open source markdown-based wiki with a very good WYSIWYG editor and flat file storage, and easy to maintain. For now I see 3 potential candidates:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;silverbullet.md&#x2F;&quot;&gt;SilverBullet&lt;&#x2F;a&gt;, still evolving but very promising&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;otterwiki.com&#x2F;&quot;&gt;OtterWiki&lt;&#x2F;a&gt;, minimal but seems powerful enough&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;js.wiki&#x2F;&quot;&gt;Wiki.js&lt;&#x2F;a&gt; the current leader, but I will wait for the v3 as the v2 to v3 migration do not seem automatic, and the development &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;selfhosted&#x2F;comments&#x2F;1mebp67&#x2F;is_wikijs_3_dead&#x2F;&quot;&gt;seems to have slowed greatly&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Suntimes, a small shell utility</title>
        <published>2022-03-03T00:00:00+00:00</published>
        <updated>2022-03-03T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://colas.nahaboo.net/code/suntimes-a-small-shell-utility/"/>
        <id>https://colas.nahaboo.net/code/suntimes-a-small-shell-utility/</id>
        
        <content type="html" xml:base="https://colas.nahaboo.net/code/suntimes-a-small-shell-utility/">&lt;p&gt;I just made a small command-line utility to display the sunrise and sunset times at a location. It can be quite useful in shell scripts.&lt;&#x2F;p&gt;
&lt;p&gt;It is a minimal Go wrapper around the &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;nathan-osman&#x2F;go-sunrise&quot;&gt;nathan-osman&#x2F;go-sunrise library&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;You can find it at my repository: &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ColasNahaboo&#x2F;suntimes&quot;&gt;GitHub - ColasNahaboo&#x2F;suntimes&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>My bash library on Github</title>
        <published>2022-02-05T00:00:00+00:00</published>
        <updated>2022-02-05T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://colas.nahaboo.net/code/my-bash-library-on-github/"/>
        <id>https://colas.nahaboo.net/code/my-bash-library-on-github/</id>
        
        <content type="html" xml:base="https://colas.nahaboo.net/code/my-bash-library-on-github/">&lt;p&gt;I have started to publish on Github, at &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ColasNahaboo&#x2F;colas-bash-lib&quot;&gt;colas-bash-lib&lt;&#x2F;a&gt;, my collection of various &lt;strong&gt;bash functions&lt;&#x2F;strong&gt; I reuse often in my bash scripts.&lt;&#x2F;p&gt;
&lt;p&gt;Fell free to copy and use in any of your projects or compilation of bash tools.&lt;&#x2F;p&gt;
&lt;p&gt;I have tried to make them the &lt;strong&gt;fastest&lt;&#x2F;strong&gt; possible, by avoiding forking sub-shells or external commands, and
benchmarking extensively to compare the possible way of coding them. Of course, I will gladly accept suggestions or code to make them faster.
But it means that error checking is often terse and minimal, and readability of the code was not a priority.&lt;&#x2F;p&gt;
&lt;p&gt;I have a kind of «anti-npm» approach, in that I &lt;strong&gt;copy&lt;&#x2F;strong&gt; these functions into my scripts rather that using hem as a true external library that I would load at runtime. It thus avoid installation issues, and the ependency problems that may arise from automated upgrades.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Bash lessons learned with AoC 2021</title>
        <published>2022-01-11T00:00:00+00:00</published>
        <updated>2022-01-11T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://colas.nahaboo.net/code/bash-lessons-learned-with-aoc-2021/"/>
        <id>https://colas.nahaboo.net/code/bash-lessons-learned-with-aoc-2021/</id>
        
        <content type="html" xml:base="https://colas.nahaboo.net/code/bash-lessons-learned-with-aoc-2021/">&lt;p&gt;I completed all the exercises of the Advent of Code 2021 in bash! (see &lt;a href=&quot;&#x2F;code&#x2F;advent-of-code-2021&quot;&gt;my previous post&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;You can find my solutions with comments in my GitHub repository at https:&#x2F;&#x2F;github.com&#x2F;ColasNahaboo&#x2F;advent-of-code-my-solutions&#x2F;tree&#x2F;main&#x2F;bash&#x2F;2021&lt;&#x2F;p&gt;
&lt;p&gt;I must say I &quot;cheated&quot; a bit. My  solution for the Day 24 was too slow in bash, and as I was a bit out of  steam, I did not try to find a smart algorithm. I just noticed that I  solved it by building a bash arithmetic expression (of 1 million  characters...) that I then evaluated in bash, and since its syntax was  exactly the one for C... I just made the bash script compile the bash  expression in C and execute it, using the C compiler as a bash  arithmetic just-in-time compiler :-)&lt;&#x2F;p&gt;
&lt;p&gt;I just discovered AoC this year, and I am impressed. Challenging, fun,  and a great way to progress. I am going to do the previous years, too,  but in &quot;real&quot; languages this time. At least ones with data structures... I will start with Go.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-i-learned&quot;&gt;What I learned:&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-learned&quot; aria-label=&quot;Anchor link for: what-i-learned&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Coding in bash is not so bad, even if it can border on insanity at times :-).&lt;&#x2F;li&gt;
&lt;li&gt;Modern bash features are often overlooked but very useful.&lt;&#x2F;li&gt;
&lt;li&gt;Passing shellcheck should be a mandatory goal for each bash programmer. I resented it at first since I thought it was adding unecessary syntaxic sugar to my code until I realized that it was a symptom that my coding style was the problem.&lt;&#x2F;li&gt;
&lt;li&gt;Use &lt;code&gt;[[...]]&lt;&#x2F;code&gt; for strings and &lt;code&gt;((...))&lt;&#x2F;code&gt; for integers other any of the legacy constructs like &lt;code&gt;[...]&lt;&#x2F;code&gt;, &lt;code&gt;test&lt;&#x2F;code&gt;, etc... The code is then much cleaner and safer (and a tad faster), as you do not have to quote as much. E.g: &lt;code&gt;[[ -z foo ]]&lt;&#x2F;code&gt; instead of &lt;code&gt;[ -z &quot;$foo&quot; ]&lt;&#x2F;code&gt;, or even &lt;code&gt;((i=j))&lt;&#x2F;code&gt; instead of &lt;code&gt;i=&quot;$j&quot;&lt;&#x2F;code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;but&lt;&#x2F;strong&gt;, this makes traditional debugging with &lt;code&gt;set -x&lt;&#x2F;code&gt; less useful as the values of variables are not displayed anymore. E.g if j is 2, the tracing of &lt;code&gt;i=&quot;$j&quot;&lt;&#x2F;code&gt; shows &lt;code&gt;i=2&lt;&#x2F;code&gt; whereas the tracing of &lt;code&gt;((i=j))&lt;&#x2F;code&gt; only shows &lt;code&gt;((i=j))&lt;&#x2F;code&gt;. This could be where a bash debugger would be useful, but I know only one, &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bashdb.sourceforge.net&#x2F;bashdb.html&quot;&gt;bashdb&lt;&#x2F;a&gt;, and it does not seem updated anymore, and I could not find a version working with bash 5.1. The &lt;code&gt;trap DEBUG&lt;&#x2F;code&gt; trick can be useful, though.&lt;&#x2F;li&gt;
&lt;li&gt;So, I tend to write now &lt;code&gt;i=$((j+k))&lt;&#x2F;code&gt; while developing code, and maybe later for production switch to the a bit more efficient &lt;code&gt;((i = j+k))&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;I avoided arrays in bash because I found out they were abysmally slow when first introduced, to the point that managing data in files with grep, sed, ... was actually faster than using arrays. But not anymore! Bash arrays should now be used as much as possible.&lt;&#x2F;li&gt;
&lt;li&gt;A lot of bash functions can &quot;map&quot; on arrays. For instance &lt;code&gt;${tab[@]&#x2F;&#x2F;x&#x2F;y}&lt;&#x2F;code&gt; will string-replace x by y in all the elements of the array tab, and is super fast.&lt;&#x2F;li&gt;
&lt;li&gt;Use arrays rather than the classic way to represent lists in bash by space-separated (or tab-separated) substrings in a  string.&lt;&#x2F;li&gt;
&lt;li&gt;Bash can have typed variables: integer ones via &lt;code&gt;declare -i&lt;&#x2F;code&gt; or &lt;code&gt;local -i&lt;&#x2F;code&gt;, and using them makes your code safer.&lt;&#x2F;li&gt;
&lt;li&gt;Bash functions can be passed variables by name, useful for efficiency to avoid copying big arrays or strings, and to provide multiple return values by modifying passed variables. But it cannot recurse as it is not a passing by reference, but by name.&lt;&#x2F;li&gt;
&lt;li&gt;Working with arrays makes using &lt;code&gt;$(...)&lt;&#x2F;code&gt; impractical, as commands are executed in a subshell and cannot access arrays anymore to update them in the parent shell. So I tend to pass the return value(s) into global variables of the same name of a function. E.g. instead of &lt;code&gt;x=$(foo)&lt;&#x2F;code&gt;, I write &lt;code&gt;foo; x=&quot;$foo&quot;&lt;&#x2F;code&gt;. Or pass variables by name to set them if I want to return multiple results.&lt;&#x2F;li&gt;
&lt;li&gt;To parse a space-separated string, the fastest is using &lt;code&gt;set&lt;&#x2F;code&gt; to map the elements in the positional parameters &lt;code&gt;$1&lt;&#x2F;code&gt;, &lt;code&gt;$2&lt;&#x2F;code&gt;, ... then the &lt;code&gt;${string#* }&lt;&#x2F;code&gt; and &lt;code&gt;${string% *}&lt;&#x2F;code&gt; operators are the fastest, closely followed by a read, the full &lt;code&gt;[[ $string =~ ([-[:digit:]]+)[[:space:]]... ]]&lt;&#x2F;code&gt; being 3 times slower. And if possible, using indexes is even faster: &lt;code&gt;${string:i:j}&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Use the faster &lt;code&gt;$(&amp;lt; filename)&lt;&#x2F;code&gt; instead of &lt;code&gt;$(cat filename)&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;To copy an associative array A1 to A2 in bash 4.4+, do:
&lt;code&gt;A1_def=$(declare -p A1) &amp;amp;&amp;amp; declare -A A2=&quot;${A1_def#*=}&quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;To access more than 9 parameters in a function: use braces: &lt;code&gt;$10&lt;&#x2F;code&gt; wont work, but &lt;code&gt;${10}&lt;&#x2F;code&gt; does.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Advent of Code 2021</title>
        <published>2021-12-07T00:00:00+00:00</published>
        <updated>2021-12-07T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://colas.nahaboo.net/code/advent-of-code-2021/"/>
        <id>https://colas.nahaboo.net/code/advent-of-code-2021/</id>
        
        <content type="html" xml:base="https://colas.nahaboo.net/code/advent-of-code-2021/">&lt;p&gt;I just discovered the &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;adventofcode.com&#x2F;&quot;&gt;Advent of code&lt;&#x2F;a&gt; coding challenge. It exists since 2015, and seems really interesting in that it is language-agnostic.&lt;&#x2F;p&gt;
&lt;p&gt;Each day a problem is described, with input files consisting of numeric values for the problem. You must submit the answer which is a number by whatever means you want.&lt;&#x2F;p&gt;
&lt;p&gt;I started to do the current 2021 challenge, in &lt;strong&gt;bash&lt;&#x2F;strong&gt; to force myself to code in a more modern style that pass &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.shellcheck.net&#x2F;&quot;&gt;shellcheck&lt;&#x2F;a&gt;. And later, i will probably do the other years in &lt;strong&gt;Go&lt;&#x2F;strong&gt; to learn it.&lt;&#x2F;p&gt;
&lt;p&gt;I publish my solutions as I code them on &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ColasNahaboo&#x2F;advent-of-code-my-solutions&#x2F;tree&#x2F;main&#x2F;bash&#x2F;2021&quot;&gt;my github&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;More info:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;adventofcode.com&#x2F;&quot;&gt;advent of code&lt;&#x2F;a&gt; (aka AOC) site&lt;&#x2F;li&gt;
&lt;li&gt;The sub-reddit  &lt;a href=&quot;&#x2F;r&#x2F;adventofcode&quot;&gt;&#x2F;r&#x2F;adventofcode&lt;&#x2F;a&gt; to discuss AOC&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
</feed>
