[pvg@server test]$ echo '$filename' $filename [pvg@server test]$ echo 'one two three' one two three
2 双引号
双引号和单引号差不多,双引号忽略大多数字符。具体来说,只是美元符号、反引号、反斜杠三种不被忽略。 a)
[pvg@server test]$ x=* [pvg@server test]$ echo '$x' $x [pvg@server test]$ echo "$x" * [pvg@server test]$ echo $x name name2 number test
b) 要赋值给add是单引号或双引号是没有区别的。
[pvg@server test]$ add="39 East 12th Street > New York, N.Y. 10003" [pvg@server test]$ echo $add 39 East 12th Street New York, N.Y. 10003 [pvg@server test]$ echo "$add" 39 East 12th Street New York, N.Y. 10003
3)可以用双引号隐藏shell单引号,反之亦然。
[pvg@server test]$ word="'hello,'he said" [pvg@server test]$ echo $word 'hello,'he said
3 反斜杠
a)用反斜杠续行
[pvg@server test]$ x=one/ > two [pvg@server test]$ echo $x onetwo
b)双引号中的反斜杠 用反斜杠去掉特殊字符的意义。
[pvg@server test]$ x=5 [pvg@server test]$ echo "/$x" $x [pvg@server test]$ echo "The Value of x is $x" The Value of x is 5
[pvg@server ~]$ echo The date and time is:`date` The date and time is:Mon Jan 5 :39:45 EAT 2009 [pvg@server ~]$ [pvg@server ~]$ echo The date and time is:$(date) The date and time is:Mon Jan 5 16:40:22 EAT 2009