【发布时间】:2017-02-16 23:15:31
【问题描述】:
在 GNU bash 版本 3.2.57 上,我发现使用 declare 打印数组变量和 nullglob 选项之间存在冲突。
这两个在我看来是非常不相关的,但这是在启用nullglob 时故意的吗?
#!/bin/bash
test () {
local FOO="xyz"
local BAR=("one" "two" "three")
declare -p FOO
declare -a -p BAR
}
echo $(test)
shopt -s nullglob
echo $(test)
shopt -u nullglob
echo $(test)
输出:
declare -- FOO="xyz" declare -a BAR='([0]="one" [1]="two" [2]="three")'
declare -- FOO="xyz" declare -a
declare -- FOO="xyz" declare -a BAR='([0]="one" [1]="two" [2]="three")'
注意中间行,当设置nullglob 时,不会发出BAR 的声明。
【问题讨论】: