ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Quote and Backslash characters in Unix Shell

Quote and Backslash characters in Unix Shell

原创 Linux操作系统 作者:yumao42 时间:2014-04-16 19:50:11 0 删除 编辑
  • Single quote '
Shell ignores any special character which is enclosed between Single Quote.
Like
    $echo 'two     rabits'
    two    rabits

When we execute the following command, we would see the annoying thing. The * is replaced by the file names in the current directory and it's not the result we would like to see.
    $i='*    is an asterisk'
    $echo $i
    load.ctl load.txt load.log is an asterisk

To overcome this, we can make use of double quotes.

  • Double quote "

Single quote ignores all the special characters while double quote ignores most. The following three characters are not ignored by double quotes. They are Dollar sign $, back quote `, and backslash \ .
Here is the example:
    $i='*   is an asterisk"
    $echo "$i"
    *   is an asterisk

  • Backslash \

Shell ignores any special meaning attached to a character by using a backslash before this character.
    $i=>
    -ksh: syntax error: `new line` unexpected
    $i=\>
    $echo $i
    >

When processing a long command, backslash can also be used for continuing lines.
    $i=one\
    >two
    $echo $i
    onetwo

  • Back quote `

Back quote tells shell to execute the command enclosed by it. However, it's an old command and not preferred for use.+

    $echo current date is `date`
    current date is Wed Apr 16 13:02:59 CEST 2014

Instead of Back quote, we use $(...) construct to substitute command and output to the command line.

    $echo current date is $(date)
    current date is Wed Apr 16 13:02:59 CEST 2014

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13738922/viewspace-1143554/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2014-04-11

  • 博文量
    2
  • 访问量
    4009