亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Bash中單引號和雙引號之間的區別

Bash中單引號和雙引號之間的區別

蠱毒傳說 2019-05-22 13:09:16
Bash中單引號和雙引號之間的區別在Bash中,單引號('')和雙引號("")之間有什么區別?
查看完整描述

3 回答

?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

如果您指的是當您回顯某些內容時會發生什么,單引號將直接回顯它們之間的內容,而雙引號將評估它們之間的變量并輸出變量的值。

例如,這個

#!/bin/shMYVAR=sometext
echo "double quotes gives you $MYVAR"echo 'single quotes gives you $MYVAR'

會給這個:

double quotes gives you sometext
single quotes gives you $MYVAR


查看完整回答
反對 回復 2019-05-22
?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

接受的答案是偉大的。我正在制作一個有助于快速理解主題的表格。解釋涉及一個簡單的變量a以及一個索引數組arr。

如果我們設定

a=apple      # a simple variablearr=(apple)  # an indexed array with a single element

然后echo在第二列中的表達式,我們將得到第三列中顯示的結果/行為。第四列解釋了這種行為。

 # | Expression  | Result      | Comments
---+-------------+-------------+--------------------------------------------------------------------
 1 | "$a"        | apple       | variables are expanded inside ""
 2 | '$a'        | $a          | variables are not expanded inside ''
 3 | "'$a'"      | 'apple'     | '' has no special meaning inside ""
 4 | '"$a"'      | "$a"        | "" is treated literally inside ''
 5 | '\''        | **invalid** | can not escape a ' within ''; use "'" or $'\'' (ANSI-C quoting)
 6 | "red$arocks"| red         | $arocks does not expand $a; use ${a}rocks to preserve $a
 7 | "redapple$" | redapple$   | $ followed by no variable name evaluates to $
 8 | '\"'        | \"          | \ has no special meaning inside ''
 9 | "\'"        | \'          | \' is interpreted inside "" but has no significance for '
10 | "\""        | "           | \" is interpreted inside ""
11 | "*"         | *           | glob does not work inside "" or ''
12 | "\t\n"      | \t\n        | \t and \n have no special meaning inside "" or ''; use ANSI-C quoting
13 | "`echo hi`" | hi          | `` and $() are evaluated inside ""
14 | '`echo hi`' | `echo hi`   | `` and $() are not evaluated inside ''
15 | '${arr[0]}' | ${arr[0]}   | array access not possible inside ''
16 | "${arr[0]}" | apple       | array access works inside ""
17 | $'$a\''     | $a'         | single quotes can be escaped inside ANSI-C quoting
18 | "$'\t'"     | $'\t'       | ANSI-C quoting is not interpreted inside ""
19 | '!cmd'      | !cmd        | history expansion character '!' is ignored inside ''
20 | "!cmd"      | cmd args    | expands to the most recent command matching "cmd"
21 | $'!cmd'     | !cmd        | history expansion character '!' is ignored inside ANSI-C quotes
---+-------------+-------------+--------------------------------------------------------------------

也可以看看:


查看完整回答
反對 回復 2019-05-22
  • 3 回答
  • 0 關注
  • 1254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號