Bash empty array expansion with `set -u`

后端 未结 11 2238
不知归路
不知归路 2020-12-12 15:37

I\'m writing a bash script which has set -u, and I have a problem with empty array expansion: bash appears to treat an empty array as an unset variable during e

11条回答
  •  没有蜡笔的小新
    2020-12-12 16:05

    Turns out array handling has been changed in recently released (2016/09/16) bash 4.4 (available in Debian stretch, for example).

    $ bash --version | head -n1
    bash --version | head -n1
    GNU bash, version 4.4.0(1)-release (x86_64-pc-linux-gnu)
    

    Now empty arrays expansion does not emits warning

    $ set -u
    $ arr=()
    $ echo "${arr[@]}"
    
    $ # everything is fine
    

提交回复
热议问题