Command substitution
$(...) or `...`
Subshell
(...)
Nested command substitution
ls -al $(echo $(ls $(pwd)))
the following is ok...
C2QSERVER lsdk # echo $(a=b;echo $a)=c;echo $bbut the following failed...
b=c
C2QSERVER lsdk # $(a=b;echo $a)=c;echo $bwhile the following will work..
bash: b=c: command not found
C2QSERVER quicksec # $($(a=b;echo $a)=c);echo $b
bash: b=c: command not found
C2QSERVER quicksec # eval $(a=b;echo $a)=c;echo $b
c
why?
bash shell只有認是直接的 a=b 這種語法是變數設定a=b; b=c; echo $b=$(eval echo \$$a)
所以 a 是變數可以變動的話,請愛用 eval 代為帶入展開即可
eval $(a=b;echo $a)=c;echo $b
h
沒有留言:
張貼留言