根据巴什手册!这意味着应该使用val1的值作为展开的参数。那么,为什么val2没有在第6行之后设置为"text“呢?
echo ${val1:-"val1 not set"} # val1 not set
echo ${val1:="val2"} # val1=val2
echo ${val1+"val1 set"} #check that val1 is set
echo ${!val1:-"val 2 not set"} # val2 not set
echo ${!val1:="text"} # val 2 should be set?
echo ${!val1:-"val2 not set"} # val2 empty
echo ${val2:-"val2 not set"} # val2 empty
val2="val2 set" # val2 set from here on
echo ${!val1:-"val2 not set"}
echo ${val2:-"val2 not set"}发布于 2016-05-11 23:57:51
这在bash 4.4中似乎是固定的:
$ bash/bash tmp.bash
val1 not set
val2
val1 set
val 2 not set
text
text <------ Line 6 now outputs text
text <------ As does line 7
val2 set
val2 set(bash/是Git存储库的本地工作目录;它包含4.4的本地构建。)
https://stackoverflow.com/questions/37174959
复制相似问题