Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754144
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类:

2009-10-13 14:17:25

  
                  - 空格
                  - 回车
                  - $
                  - #
                  - *
                  - < >
            在unix系统中,许多特殊字符对shell来说都有特殊含义,例如,空格是命令和参数的分割符。回车会发送给shell执行命令的信号,$符号被用来显示与变量名相关联的值。
            在一些特殊的情况下,你不想要shell去解释这些特殊字符的特殊含义。你只要求字面上的意义。因此,unix必须提供一种机制来忽略或消除一个指定的字符的含义。这种机制就叫做引用。
            8.2 引用符号
            反斜杠 \
            单引号 ‘
            双引号 “
            反斜杠消除紧跟在它后面的特殊字符的特殊意义。
            单引号(’)会消除特殊字符的特殊含义。在单引号包围之中的所有的特殊字符的特殊含义都会被忽略。单引号不能被忽略,它要被用来关闭被引用的字符串。
            双引号(”)的包容性要差一点,大多数的字符都可以使用双引号来去除特殊含义。只有$符号(当其被用来作为变量和命令替代的时候),和反斜杠例外。你可以在双引号中使用反斜杠来除掉 $号的特别含义
            8.3 引用-- \
                  语法:
                  \ ??除去下一个字符的特别含义
                  例子:
                  $ echo the \ \ escapes the next character
                  the \ escapes the next character
                  $ color=red\ white\ and\ blue
                  $ ehco the value of \ $ colore is $color
                  the value of $colore is red white and blue
                  $ echo one two \
                  >three four
                  one two three four
            反斜杠会忽略下一个特殊字符的特殊含义。没有任何的例外。
            8.4 引用-‘
                  语法:
                  ‘ ???除去包括在单引号中的所有字符的特殊含义。
                  例子:
                  $ color =’red white and blue’
                  $ echo ‘the value of \$colore is $colore’
                  the value of $color is $color
                  $ echo ‘the value of $color is ‘ $color
                  the value of $color is red whie and blue
                  $ echo ‘this doesn’t work’
                  >ctrl + c
                  $ echo ‘***************”
                  *************
            单引号会去除所有的包含在其中的特殊字符的特别含义。
            8.5 引用 - “
                  “ ???去除包含在其中的特殊字符的特别含义,但\,$,和 “除外。
                  例子:
                  $ color = ‘red white and blue”
                  $ echo “the value of \$colore is $color”
                  the value of $volor is red white and blue
                  $ cur_dir=”$LOGNAME – your current directory is $(pwd)”
                  $ echo $cur_dir
                  user3 – your current directory is /home/user3/tree
                  $ echo “they’re all here ,\\ , ‘, \” “
                  they’re all here,/, ‘, “
            双引号引用不如单引号引用全面,大多数的特别字符都会被忽略,例外是你可以进行变量替代,$variable,和命令替代, $(cmd).
            当你使用双引号引用的时候,你也许会想要忽略这些特殊字符的含义。因而,反斜杠(\)同时也保持了它的特殊含义,可以用它来除去特殊字符$,或’的特殊含义。前提是他们出现在双引号当中。
            注意:引用机制只能在单个命令行中使用。
            8.6 总结
                  机制 ??????目标
                  反斜杠 ?????忽略下一个字符
                  单引号 ?????忽略所有的在‘‘中的字符
                  双引号 ?????忽略所有的在“”中的字符,除了 \, $,
                  ????????{变量名}, 和$(comand)。
阅读(541) | 评论(0) | 转发(0) |
0

上一篇: Shell 高级特征

下一篇:输入输出重定向

给主人留下些什么吧!~~