shell如何判斷變量是否定義并做相應轉換

shell如何判斷變量是否定義并做相應轉換:

   +----------------------+------------+-----------------------+-----------------------------+
   |   if VARIABLE is:    |        set       |         empty         |        unset          |
   |                      | Set and Not Null |      Set But Null     |        Unset          |
   +----------------------+------------------+-----------------------+-----------------------+
 - |  ${VARIABLE-default} | $VARIABLE        |          ""           |       "default"       |
 = |  ${VARIABLE=default} | $VARIABLE        |          ""           | $(VARIABLE="default") |
 ? |  ${VARIABLE?default} | $VARIABLE        |          ""           |       exit 127        |
 + |  ${VARIABLE+default} | "default"        |       "default"       |          ""           |
   +----------------------+------------------+-----------------------+-----------------------+
:- | ${VARIABLE:-default} | $VARIABLE        |       "default"       |       "default"       |
:= | ${VARIABLE:=default} | $VARIABLE        | $(VARIABLE="default") | $(VARIABLE="default") |
:? | ${VARIABLE:?default} | $VARIABLE        |       exit 127        |       exit 127        |
:+ | ${VARIABLE:+default} | "default"        |          ""           |          ""           |
   +----------------------+------------------+-----------------------+-----------------------+

參考文檔 http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 官網(wǎng) 中文版本 好的網(wǎng)站 Content-type: text/htmlBASH Section: User ...
    不排版閱讀 4,712評論 0 5
  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,562評論 19 139
  • 背景: 閱讀新聞 12C CDB模式下RMAN備份與恢復 [日期:2016-11-29] 來源:Linux社區(qū) 作...
    陽屯okyepd閱讀 3,845評論 0 7
  • 2017-04-07毛毛蟲蝶變第17天 【今日學習】 媽媽讀《易經(jīng)》21-30卦、《黃帝內(nèi)經(jīng)》生氣通天論篇第三、《...
    王海艷閱讀 346評論 0 1
  • 在不同的時間不同的地點收到過不同的人寫過的情書,回首想想,自己卻從未動手寫過一封。 因為在這之前我還沒有等到我要...
    be4726ae607e閱讀 284評論 0 0

友情鏈接更多精彩內(nèi)容