asdf banned_commands
github.com
github.com
Now? I just pick a minimum version of Python and limit myself to the standard library (Python package management still sucks) and occasional subprocesses (ex. preferring to invoke the zstd cli vs installing the Python package). This tends to be more verbose than shell scripting, but also much clearer - especially when compared to using single-letter flag arguments for options I seldom use.
I also don't generally trust those I share my scripts with to have a deep enough understanding of shell scripting to ensure portability and safety (argument parsing, quoting, and iterating over paths).
A colleague of mine said it pretty well - if your script is doing even minutely complex with jq, it’s probably time to reach for Python.
But it is ironic that the script uses `echo` to show a message that `printf` is preferred to `echo`. I guess what is meant is that `printf` is preferred to `echo -[en]`.
echo "banned command $cmd: $output"
This is non-portable if there is any possibility that these variables contain backslashes. dash$ x="foo\nasd"
dash$ echo "$x"
foo
asd
dash$ printf "%s\n" "$x"
foo\nasd
dash$
zsh% x="foo\nasd"
zsh% echo "$x"
foo
asd
zsh% printf "%s\n" "$x"
foo\nasd
zsh%
bash$ x="foo\nasd"
bash$ echo "$x"
foo\nasd
bash$ printf "%s\n" "$x"
foo\nasd
bash$ bash$ echo -e $x
foo
asd
bash$From POSIX:
>echo - write arguments to standard output
>If the first operand is -n, or if any of the operands contain a <backslash> character, the results are implementation-defined.
In other words, they control where this script runs and there is no need to run it on more than one platform, so it's okay for it to be non-portable.
In the end, it was much easier to just proclaim GNU coreutils as a dependency everywhere, and use g-prefixed versions of commands (gfind, ggrep, and so on).
I had to stick to (most of) POSIX across Unixes with ksh88/mksh/pdksh back in the day when my work had to be portable across Linux, BSD, Solaris, HP-UX, and AIX. I could rely on process substitution, etc. but stay vanilla outside the shell itself.
Honestly the only really annoying thing to me was that sed -i didn’t mean in place, but even then it wasn’t reliably atomic IIRC.
Handling the actual OS commands was much harder. Separate commands instead of getent (maybe getpw was one?) on HP-UX pops into my head.
0 - https://github.com/asdf-vm/asdf/blob/master/test/banned_comm...
(1) https://github.com/bats-core/bats-core/blob/ca5a2dce94/lib/b...
(2) https://github.com/bats-core/bats-core/blob/ca5a2dce94/lib/b...
(3) bash automatic testing system.
Historically, the list of architectures that public github action runners make available has been quite limited. Having an alpine runner to surface unsupported commands would be a huge win.
That being said, it's very useful as a plugin dev to have this test suite while working on a WSL2/Ubuntu so that I don't need to run a full CI build every time
It would be better to ensure POSIX shell script compliance by running the scripts with dash shell instead.