在GNU bash版本3.2.57上,我看到使用declare
打印数组变量和nullglob
选项之间存在冲突。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
被发射。
啊,有趣。我没有意识到我需要引用'$()'。当我允许时,我会在几分钟内接受你的回答。谢谢! – rgov