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

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

Double quotes

Double quotes behave similarly to single quotes, but they perform certain kinds of expansion within them, for shell variables and substitutions. This can be used to include the value of a variable as part of a literal string:

$ echo "This is my login shell: $SHELL"
This is my login shell: /bin/bash

Compare this to the literal output of single quotes:

$ echo 'This is my login shell: $SHELL'
This is my login shell: $SHELL

Other kinds of parameter expansion within double quotes are possible, which we will examine in later chapters.

You can include a literal dollar sign or backslash in a string by escaping it:

$ echo "Not a variable: \$total"
Not a variable: $total
$ echo "Back\\to\\back\\slashes"
Back\to\back\slashes

Exclamation marks are a special case, due to history expansion; you will generally need to quote them with a backslash or single quotes instead of double quotes:

$ echo "Hello $USER"'!!'
Hello bashuser!!

For historical reasons, you will also need to escape backtick characters (`):

$ echo "Backticks: \`\`\`"
Backticks: ```
主站蜘蛛池模板: 恭城| 全州县| 新密市| 响水县| 乐山市| 聂荣县| 收藏| 巴楚县| 都兰县| 岐山县| 塔河县| 政和县| 乃东县| 巧家县| 耿马| 健康| 繁峙县| 安泽县| 邯郸市| 河西区| 察隅县| 无棣县| 天全县| 应城市| 若尔盖县| 佛冈县| 固镇县| 凤阳县| 绿春县| 宁都县| 岫岩| 邛崃市| 铜山县| 雅安市| 沁源县| 津市市| 偏关县| 锡林浩特市| 通河县| 奉节县| 锦州市|