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

 

转载于:https://www.cnblogs.com/gavin-he/archive/2013/04/16/3024094.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值