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

  • 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: ```
主站蜘蛛池模板: 长海县| 安丘市| 姜堰市| 南溪县| 潮州市| 将乐县| 任丘市| 北京市| 贡觉县| 丹江口市| 瑞金市| 霍州市| 什邡市| 木兰县| 舟山市| 始兴县| 巴彦县| 阳谷县| 白朗县| 津南区| 莱西市| 蒙自县| 吉隆县| 彰武县| 巫溪县| 庆阳市| 锡林浩特市| 大港区| 牡丹江市| 镇赉县| 民县| 象山县| 施甸县| 策勒县| 五台县| 桓仁| 襄汾县| 合肥市| 兖州市| 嘉鱼县| 乌鲁木齐市|