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

  • 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
主站蜘蛛池模板: 静宁县| 芜湖县| 乌兰察布市| 永吉县| 五家渠市| 新津县| 涞源县| 岗巴县| 正阳县| 北京市| 德兴市| 永靖县| 宁城县| 眉山市| 谢通门县| 盐山县| 台山市| 兴安盟| 神农架林区| 大庆市| 会昌县| 莱西市| 丹巴县| 乐亭县| 宣城市| 新泰市| 松滋市| 贡嘎县| 承德市| 太仓市| 济南市| 木兰县| 拜泉县| 肃南| 正镶白旗| 哈密市| 临朐县| 尤溪县| 余干县| 洪洞县| 镶黄旗|