[Linux] Single quote vs. Double quote inside Shell script

Single Quote

Use single quote when you want to literally print everything inside the single quote. Even the special variables such as $HOSTNAME will be print as $HOSTNAME instead of printing the name of the Linux host.

$ echo 'Hostname=$HOSTNAME ;  Current User=`whoami` ; Message=\$ is USD'
Hostname=$HOSTNAME ;  Current User=`whoami` ; Message=\$ is USD

Double Quote

Use double quotes when you want to display the real meaning of special variables.

$ echo "Hostname=$HOSTNAME ;  Current User=`whoami` ; Message=\$ is USD"
Hostname=dev-db ;  Current User=ramesh ; Message=$ is USD

Double quotes will remove the special meaning of all characters except the following:

  • $ Parameter Substitution.
  • ` Backquotes
  • \$ Literal Dollar Sign.
  • Literal Backquote.
  • \” Embedded Doublequote.
  • \\ Embedded Backslashes.
  1. Hack 87. Single Quote and Double Quote Inside Shell Script
posted @ 2012-10-16 11:36  UniMouS  阅读(783)  评论(0编辑  收藏

版权所有 © 2011-2012 方一曙

Copyright © 2011-2012 Fang Yishu (UniMouS)