Bug#922423: initscripts: formatting of scripts
Thorsten Glaser
tg at evolvis.org
Mon Mar 17 20:31:22 GMT 2025
On Mon, 17 Mar 2025, Mark Hindley wrote:
> Scripts should follow the style produced by shfmt(1)
FWIW, never heard of that tool.
> - case indented
Don’t indent case, it’s useless and just adds clutter.
You cannot have something other than the pattern inside, so:
case $foo in
(bar)
echo bla
;;
(*)
echo nope
;;
esac
(If all scriptlets are extremely short, merging on less
lines is possible.)
> - prefer '[ ]' to test(1) or builtin
I personally, as the maintainer of a shell and a plethora of
scripts, recommend people to prefer test(1) over [ … ] instead
because the latter “looks like” special syntax but [(1) isn’t
(unlike [[ … ]], which they may also know), and that leads to
insecure code, whereas test(1) looks more like a normal program
whose arguments need proper quoting. I’m aware that this is a
minority opinion, though.
http://www.mirbsd.org/man9/style has bits applying to shell
scripts as well.
bye,
//mirabilos
--
„Cool, /usr/share/doc/mksh/examples/uhr.gz ist ja ein Grund,
mksh auf jedem System zu installieren.“
-- XTaran auf der OpenRheinRuhr, ganz begeistert
(EN: “[…]uhr.gz is a reason to install mksh on every system.”)
More information about the Debian-init-diversity
mailing list