shell學習筆記(2)替換命令··與()的區別

來源:互聯網
上載者:User

標籤:

·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)替換命令··與()的區別

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.