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 ~]# 

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