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

  • 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: ```
主站蜘蛛池模板: 古丈县| 宜州市| 南开区| 鹤山市| 南城县| 化德县| 察雅县| 高陵县| 乾安县| 锡林郭勒盟| 兰州市| 白玉县| 长宁县| 岳阳县| 肇源县| 天祝| 华安县| 北安市| 新竹市| 天柱县| 盘锦市| 乌兰县| 德惠市| 长寿区| 喀喇沁旗| 兴安县| 辛集市| 五华县| 壤塘县| 长宁区| 正阳县| 石城县| 灵山县| 五指山市| 崇明县| 宜春市| 昌宁县| 汾阳市| 政和县| 嫩江县| 新巴尔虎右旗|