Single and Double quotes.
Guidelines for quoting command arguments
- \
- prevent the shell from expanding any single special character.
- ' '
- prevent the shell from expanding all special characters enclosed in this string except !.
- " "
- prevent the shell from expanding any enclosed special character except $, ` and !.
Single quotes limit substitution. We can place variables in double quoted text and the shell still performs substitution.
[me@linuxbox me]$ echo "My host name is $HOSTNAME."
My host name is linuxbox.
My host name is linuxbox.
[me@linuxbox me]$ echo 'My host name is $HOSTNAME.'
My host name is $HOSTNAME.
My host name is $HOSTNAME.
Double quotes do not suppress the substitution of words that begin with "$" but they do suppress the expansion of wildcard characters. For example, try the following:
[me@linuxbox me]$ echo *
anaconda-ks.cfg clear.sh config.txt date_marker ftpftp1 list1 list2 list3 list4 list5 list6 post-install post-install.log script status textfile[me@linuxbox me]$ echo "*"
*
Quoting a single character
There is another quoting character you will encounter. It is the backslash. The backslash tells the shell to "ignore the next character." Here is an example:
[me@linuxbox me]$ echo "My host name is \$HOSTNAME."
My host name is $HOSTNAME.
My host name is $HOSTNAME.
By using the backslash, the shell ignored the "$" symbol. Since the shell ignored it, it did not perform the substitution on $HOSTNAME. Here is a more useful example:
[me@linuxbox me]$ echo "My host name is \"$HOSTNAME\"."
My host name is "linuxbox".
My host name is "linuxbox".
As you can see, using the \" sequence allows us to embed double quotes into our text.
Comments
Post a Comment