zlacker

[parent] [thread] 0 comments
1. ndsipa+(OP)[view] [source] 2026-01-07 18:02:36
The example FOR loop in BASH is missing a trick to make it easier to read:

  for i in {1..10}; do
    echo $i
  done
(Though I prefer using printf than echo as it's more capable and POSIX compliant)

I write far too much stuff in BASH, but for me it's just not worth moving to using a different shell due to its ubiquity. There's also the question of "will this still run easily in 20 years". Of course, BASH is a nightmare for bugs and foot-guns unless you make a point of defensive coding (e.g. surround variables with double-quotes and using Shellcheck to point out common errors).

By the way, the article goes on to mention the large number of options to "ls". Don't try to parse the output of "ls" in scripts as there's better ways to do things: https://mywiki.wooledge.org/ParsingLs

[go to top]