官术网_书友最值得收藏!

  • Bash Quick Start Guide
  • Tom Ryder
  • 174字
  • 2021-07-23 16:58:57

Single quotes

Using single quotes, we could write the commands like this, which is perhaps more readable than the backslashes version, and creates files with identical names:

$ touch 'important files'
$ touch 'Testfile<Tom>.doc'
$ touch 'Review;Final.doc'
$ touch '$$$Money.doc'

Unlike backslashes, single quotes can escape a newline in a word:

$ echo 'quotes
> foo
> bar'
quotes
foo
bar

How do we use a single quote (') as a literal character between two single quotes? If you are coming to Bash from a language such as Perl or PHP, you might try it like this, with a backslash, but that doesn't work:

$ echo 'It\'s today'
>

This is because backslash is not treated specially within single quotes. Doubling the single quote doesn't work, either:

$ echo 'It''s today'
Its today

In this case, Bash just sees two single-quoted strings, It and s today, and pushes them together as one word. The way to do it is to use a backslash outside of the single quotes:

$ echo 'It'\''s today'
It's today
主站蜘蛛池模板: 荥阳市| 沭阳县| 府谷县| 茂名市| 抚州市| 琼结县| 诸暨市| 丹巴县| 临汾市| 随州市| 内江市| 宁明县| 沙田区| 乌拉特前旗| 清徐县| 长乐市| 田林县| 凌海市| 桐城市| 合山市| 白银市| 博爱县| 石楼县| 许昌县| 焦作市| 菏泽市| 玛纳斯县| 竹北市| 凤翔县| 亚东县| 郧西县| 南澳县| 巴青县| 光泽县| 遂平县| 厦门市| 辽宁省| 盘锦市| 乐东| 罗平县| 陆丰市|