Calvin's Tech Space

          成于堅忍,毀于浮躁

             :: 首頁 :: 聯系 :: 聚合  :: 管理
          一個here document就是一段帶有特殊目的的代碼段. 它使用IO重定向的形式將一個命令序列傳遞到一個交互程序或者命令中, 比如frp,cat或者ex文本編輯器.
          interactive-program <<delimiter
          command #1
          command #2
          ...
          delimiter

          默認情況下,變量會被替換:
          ?$ cat << EOF
          ?> Working dir $PWD
          ?> EOF
          ?Working dir /home/user

          如果delimiter用雙引號引起來,則不會有變量替換:
          ?$ cat << "EOF"
          ?> Working dir $PWD
          ?> EOF
          ?Working dir $PWD

          重定向 符號 << 可以使用 <<- ,在這種情況下,heredoc 文本中的前導 tab 字符會被刪除,但是空格不會被刪除!

          注意:
          結束標記前一定不能有任何空格或者tab,否則執行失敗!

          heredoc 另外一個比較有用的是顯示消息塊,如Usage信息:
          cat <<End-of-message
          -------------------------------------
          This is line 1 of the message.
          This is line 2 of the message.
          This is line 3 of the message.
          This is line 4 of the message.
          This is the last line of the message.
          -------------------------------------
          End-of-message

          參考:
          http://tldp.org/LDP/abs/html/here-docs.html
          http://febird.iteye.com/blog/588509
          http://en.wikipedia.org/wiki/Here_document
          posted on 2011-05-26 18:12 calvin 閱讀(397) 評論(0)  編輯  收藏 所屬分類: Linux
          主站蜘蛛池模板: 滕州市| 巴马| 亳州市| 繁昌县| 横峰县| 剑阁县| 涟源市| 民县| 扎赉特旗| 齐河县| 青冈县| 县级市| 钟山县| 兴仁县| 公主岭市| 阳江市| 西华县| 文山县| 滦南县| 镇雄县| 五原县| 正蓝旗| 依安县| 微山县| 德兴市| 屏南县| 海阳市| 黑河市| 三门县| 伊金霍洛旗| 清远市| 巴塘县| 太仆寺旗| 永济市| 滨海县| 西城区| 天水市| 东乡| 普格县| 建水县| 恩施市|