News for hackers. Stuff that matters.
Re:Shellcheck finds bugs in your shell scripts by augusto-moura on Thursday November 23, 2023 @04:24PM (#38397746)
The problem with "${arr[@]}" only exists on bash 3 and before, since bash 4, [@] will never throw unbound variables even in cases where the variable is truly undefined. This is still a problem however, because 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!).

In any case, you can workaround expanding empty arrays throwing unbound by using the ${var+alter} expansion

  echo "${arr+${arr[@]}}"
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.