標籤:
·CMD·在執行的時候,shell不管··中的內容是什麼,先進性解釋,再把解釋後的最終結果送給shell,如果解釋後的結果不是shell可以行的命令,就會報錯。但是僅僅把cmd的執行結果作為文本輸出,就沒有問題。
如:
[[email protected] root]# i=0
[[email protected] root]# name=pwd
[[email protected] root]# `$i` # $i已經得到了結果0,再把0送給shell執行,當然出錯啦
-bash: 0: command not found
[[email protected] root]# `$name` # $name就已經相當於執行了pwd,得到/root,此時再把/root送給shell執行,當然不可解釋啦
-bash: /root: is a directory
[[email protected] root]# echo "`$name`" # 把$name執行後的內容作為文本輸出
/root
[[email protected] root]# `pwd`
-bash: /root: is a directory
(CMD)在執行時,如果cmd是命令,則直接對給shell去執行,如果如果是變數取值,則僅作第一層的字面解釋後丟給shell
如:
[[email protected] root]# i=0
[[email protected] root]# name=pwd
[[email protected] root]# ($i) # 解釋後得到0,再把0送給shell,當然出錯啦.
-bash: 0: command not found
[[email protected] root]# ($name) # 解釋後得到pwd,再把pwd送給shell執行.
/root
[[email protected] root]# (pwd) # 直接把pwd丟給shell去執行
/root
shell學習筆記(2)替換命令··與()的區別