Re:Shellcheck finds bugs in your shell scripts
by mmsc on Thursday November 23, 2023 @04:33PM
(#38397820)
The problem with "${arr[@]}" only exists on bash 3 and before, since bash 4
4.4 fixed it: $ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
$ declare -A arr
$ set -u
$ "${arr[@]}"
-bash: arr[@]: unbound variable
Re:Shellcheck finds bugs in your shell scripts
by augusto-moura on Thursday November 23, 2023 @05:29PM
(#38398352)
Ah, that's true, I couldn't recall which version fixed it. Usually I assume v4 because any other distro automatically updates to the latest v4 version or latest version af all.
macOS is the only one out there missing on this. The other big feature that was only added after bash 3 and is missing on mac is associative arrays
Re:Shellcheck finds bugs in your shell scripts
by extraduder_ire on Friday November 24, 2023 @07:07AM
(#38403126)
> macOS, to this day, still installs bash v3 by default and doesn't update it automatically (absolute madness, the last release of bash 3 it's from 20 years ago!).
GPL3, buddy. You can use brew to install a newer version and somewhat hide the old one.
In any case, you can workaround expanding empty arrays throwing unbound by using the ${var+alter} expansion