4 ms·
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 un
by augusto-moura 3y ago
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[@]}}"
- mmsc 3y agoThe 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
- augusto-moura 3y agoAh, 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
- extraduder_ire 3y ago> 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.