3 ms·
Double brackets are less portable. For example musl linux does not come with bash by default, and your script fails. When unsure, use shellcheck.
by stabbles 9mo ago
Double brackets are less portable. For example musl linux does not come with bash by default, and your script fails.
When unsure, use shellcheck.
- a3w 9mo ago[[ is built in, so "test[" as an /usr/bin artifact never exists? (What to call that proposed program, test2, or test[ ?)
- duskdozer 9mo agoYou mean shellcheck will detect when single brackets won't be enough? I've also just defaulted to double because I never really looked into it
- stabbles 9mo agoYeah, if you set the shebang `#!/bin/sh` (which is portable), shellcheck will complain about double brackets. It also helps you do quoting correctly when using single brackets.
- duskdozer 9mo agoI see. I've always just used `#!/usr/env/bin bash`. I wonder if there's a directive to hint at incompatibilities without changing it? I'll have to see. And this isn't meant snarkily - why should I care if my scripts are portable? I've worked on a number of different devices and types but have seemingly always had access to bash.