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

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

如何在單引號字符串中使用變量?

如何在單引號字符串中使用變量?

如何在單引號字符串中使用變量?我只是想知道如何在單引號內回顯變量(我使用單引號,因為字符串中有引號)。     echo 'test text "here_is_some_test_text_$counter" "output"' >> ${FILE}任何幫助將不勝感激
查看完整描述

3 回答

?
呼喚遠方

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

變量以雙引號字符串擴展,但不在單引號字符串中擴展:

 $ name=World

 $ echo "Hello $name"
 Hello World

 $ echo 'Hello $name'
 Hello $name

如果您只需切換引號,請執行此操作。

如果您更喜歡使用單引號來避免額外的轉義,則可以在同一參數中混合和匹配引號:

 $ echo 'single quoted. '"Double quoted. "'Single quoted again.'
 single quoted. Double quoted. Single quoted again.

 $ echo '"$name" has the value '"$name"
 "$name" has the value World

適用于您的案例:

 echo 'test text "here_is_some_test_text_'"$counter"'" "output"' >> "$FILE"


查看完整回答
反對 回復 2019-08-28
?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

使用printf:

printf 'test text "here_is_some_test_text_%s" "output"\n' "$counter" >> ${FILE}


查看完整回答
反對 回復 2019-08-28
?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

使用heredoc:

cat << EOF >> ${FILE}test text "here_is_some_test_text_$counter" "output"EOF


查看完整回答
反對 回復 2019-08-28
  • 3 回答
  • 0 關注
  • 1028 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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