5.2. Escaping

1、Example 5-2(怎么样才能显示下面这个 $escape ?)

 


      54 escape=$'\033'                    # 033 is octal for escape.

      55 echo "\"escape\" echoes as $escape"

      56 #                                   no visible output.

 

2、echo -e的用法:


[mdx@localhost abs-exercises]$ echo "\n"

\n

[mdx@localhost abs-exercises]$ echo -e "\n"

[mdx@localhost abs-exercises]$

[mdx@localhost abs-exercises]$ echo "\\"

\

[mdx@localhost abs-exercises]$ echo -e "\\"

\

[mdx@localhost abs-exercises]$ echo -e '\\'

\

[mdx@localhost abs-exercises]$ echo  '\\'

\\

3、可是说是一些非常烦人的用法,不用去记它,平常也用不着吧。

Note The behavior of \ depends on whether it is itself escaped, quoted, or

     appearing within command substitution or a here document.


        1                       #  Simple escaping and quoting

        2 echo \z               #  z

        3 echo \\z              # \z

        4 echo '\z'             # \z

        5 echo '\\z'            # \\z

        6 echo "\z"             # \z

        7 echo "\\z"            # \z

        8

        9                       #  Command substitution

       10 echo `echo \z`        #  z

       11 echo `echo \\z`       #  z

       12 echo `echo \\\z`      # \z

       13 echo `echo \\\\z`     # \z

       14 echo `echo \\\\\\z`   # \z

       15 echo `echo \\\\\\\z`  # \\z

       16 echo `echo "\z"`      # \z

       17 echo `echo "\\z"`     # \z

       18

       19                       # Here document

       20 cat <<EOF

       21 \z

       22 EOF                   # \z

       23

       24 cat <<EOF

       25 \\z

       26 EOF                   # \z

       27

       28 # These examples supplied by St?phane Chazelas.

4、\可以起到续行符的作用,文中的叙述:

The escape also provides a means of writing a multi-line command. Normally,

each separate line constitutes a different command, but an escape at the end of

a line escapes the newline character, and the command sequence continues on to

the next line.

例如:下面的dir这个命令被分成3行来写,每行一个字符:)


[mdx@localhost abs-exercises]$ d\

> i\

> r

ch4-2.txt  ctrl-h.sh  ex2-1.sh  ex2-3.sh  ex4-5.sh  ex4-7.sh  plan2.txt

ch5-2.txt  ctrl-m.sh  ex2-2.sh  ex4-2.sh  ex4-6.sh  ex5-2.sh  plan.txt

[mdx@localhost abs-exercises]$ dir

ch4-2.txt  ctrl-h.sh  ex2-1.sh  ex2-3.sh  ex4-5.sh  ex4-7.sh  plan2.txt

ch5-2.txt  ctrl-m.sh  ex2-2.sh  ex4-2.sh  ex4-6.sh  ex5-2.sh  plan.txt