shell中quotes的不同作用

一.shell中quotes的类型

  1 .backslash \

  2. single quotes' '

  3.double quotes  " "

  4. back quotes ` `

The back quote is not used for quoting characters. That character is used for command substitution, where the characters between them are executed by the shell and the results is inserted on that line

 

$ echo the date is `date`

 

二 各类quotes 的作用

   1 .backslash \ :       The backslash is the "strongest" method of quotation.It works when every other method fails.

      $ touch \*\*\*    #creates a file named ***

      $rm ***            #the shell will interprete it, thus *** means  all the files in the current directory

      $rm \*\*\*        # the backslash prevent the * from interpreting by the shell, thus this cmd rm the file whose name is ***

 

   2.  single quotes ' '  : Strong Quoting,   Inside the single quotes, you can include almost all meta-characters:

     $echo 'What the *heck* is a $ doing here???'
     What the *heck* is a $ doing here???


  3 double quotes ""  Weaker Quoting, doesn't expand meta-characters like "*" or "?," but does expand variables and does command                   

                      substitution. 

       $ echo "Is your home directory $HOME?"

        Is your home directory /home/kreskin/u0/barnett?

      $ echo "Your current directory is `pwd`"

         Your current directory is /home/kreskin/u0/barnett


三 组合操作

     1. Quotes with Quotes      

       If you want to quote single quotes, use double quotes around it. To quote double quotes, use single quotes. Heck, it's easier to show you:

% echo "Don't do that"
Don't do that
% echo 'The quote of the day is: "TGIF"'
The quote of the day is: "TGIF"

        

Further more: http://www.grymoire.com/Unix/Quote.html

 

posted @ 2013-04-16 14:42  舟乍舟孟  阅读(641)  评论(0编辑  收藏  举报