shell——$後加引號有什麼用($"string"和$'string')

  1. 如果沒有特殊定製bash環境或有特殊需求,$"string"和"string"是完全等價的
  2. $後接單引號的$‘string’,這在bash中被特殊對待:會將某些反斜線序列(如\n,\t,",'等)繼續轉義,而不認爲它是字面符號(如果沒有$符號,單引號會強制將string翻譯爲字面符號,包括反斜線)。

例:

[root@python ~]# echo $"a\nb"
a\nb
[root@python ~]# echo $'a\nb'
a
b
[root@python ~]# echo 'a\nb'
a\nb
[root@python ~]# echo "a\nb"
a\nb
[root@python ~]# 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章