$ {!name:= val}没有设置$ name?

时间:2016-05-11 23:38:56

标签: bash

根据bash手册,!意味着val1的值应该用作扩展的参数。那么为什么在第6行之后val2没有设置为“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"}

1 个答案:

答案 0 :(得分:4)

这似乎已在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的本地版本。)