Chapter 5. Quoting
1、那个IFS是什么意思?
Example 5-1. Echoing Weird Variables
1 #!/bin/bash
2 # weirdvars.sh: Echoing weird variables.
3
4 var="'(]\\{}\$\""
5 echo $var # '(]\{}$"
6 echo "$var" # '(]\{}$" Doesn't make a difference.
7
8 echo
9
10 IFS='\'
11 echo $var # '(] {}$" \ converted to space. Why?
12 echo "$var" # '(]\{}$"
13
14 # Examples above supplied by Stephane Chazelas.
15
16 exit 0
|
|
2、
[mdx@localhost mdx]$ echo '\''
>
>
>
...
|
|
(回车就显示>,永远不会出现',除非'没有在两个'之中)
Since even the escape character (\) gets a literal interpretation within single quotes, trying to enclose a single quote within single quotes will not yield the expected result.
1 echo "Why can't I write 's between single quotes"
2
3 echo
4
5 # The roundabout method.
6 echo 'Why can'\''t I write '"'"'s between single quotes'
7 # |-------| |----------| |-----------------------|
8 # Three single-quoted strings, with escaped and quoted single quotes between.
9
10 # This example courtesy of Stéphane Chazelas.
|
|
3、太令人难以把握了,没有规律吗?
Of more concern is the inconsistent behavior of "\" within double quotes.
bash$ echo hello\!
hello!
bash$ echo "hello\!"
hello\!
bash$ echo -e x\ty
xty
bash$ echo -e "x\ty"
x y
|
|
4、生词:
Quoting can also suppress echo's "appetite" for newlines.
Weird
discrete