1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Escaping</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Advanced Bash-Scripting Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="Quoting"
HREF="quoting.html"><LINK
REL="PREVIOUS"
TITLE="Quoting"
HREF="quoting.html"><LINK
REL="NEXT"
TITLE="Exit and Exit Status"
HREF="exit-status.html"><META
HTTP-EQUIV="Content-Style-Type"
CONTENT="text/css"><LINK
REL="stylesheet"
HREF="common/kde-common.css"
TYPE="text/css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1"><META
HTTP-EQUIV="Content-Language"
CONTENT="en"><LINK
REL="stylesheet"
HREF="common/kde-localised.css"
TYPE="text/css"
TITLE="KDE-English"><LINK
REL="stylesheet"
HREF="common/kde-default.css"
TYPE="text/css"
TITLE="KDE-Default"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#AA0000"
VLINK="#AA0055"
ALINK="#AA0000"
STYLE="font-family: sans-serif;"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="quoting.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Quoting</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="exit-status.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="ESCAPINGSECTION"
></A
>5.2. Escaping</H1
><P
><A
NAME="ESCP"
></A
><I
CLASS="FIRSTTERM"
>Escaping</I
> is a method
of quoting single characters. The <SPAN
CLASS="TOKEN"
>escape</SPAN
>
(<SPAN
CLASS="TOKEN"
>\</SPAN
>) preceding a character tells the shell to
interpret that character literally.</P
><DIV
CLASS="CAUTION"
><TABLE
CLASS="CAUTION"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="common/caution.png"
HSPACE="5"
ALT="Caution"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>With certain commands and utilities, such as <A
HREF="internal.html#ECHOREF"
>echo</A
> and <A
HREF="sedawk.html#SEDREF"
>sed</A
>, escaping a character may have the
opposite effect - it can toggle on a special meaning for that
character.</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="VARIABLELIST"
><P
><B
><A
NAME="SPM"
></A
>Special meanings of certain
escaped characters</B
></P
><DL
><DT
>used with <B
CLASS="COMMAND"
>echo</B
> and
<B
CLASS="COMMAND"
>sed</B
></DT
><DD
><P
></P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\n</SPAN
></DT
><DD
><P
>means newline</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\r</SPAN
></DT
><DD
><P
>means return</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\t</SPAN
></DT
><DD
><P
>means tab</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\v</SPAN
></DT
><DD
><P
> means vertical tab</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\b</SPAN
></DT
><DD
><P
>means backspace</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\a</SPAN
></DT
><DD
><P
>means <I
CLASS="FIRSTTERM"
>alert</I
> (beep or flash)</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\0xx</SPAN
></DT
><DD
><P
><A
NAME="OCTALREF"
></A
>translates to the
octal <A
HREF="special-chars.html#ASCIIDEF"
>ASCII</A
>
equivalent of <TT
CLASS="REPLACEABLE"
><I
>0nn</I
></TT
>, where
<TT
CLASS="REPLACEABLE"
><I
>nn</I
></TT
> is a string of digits</P
><DIV
CLASS="IMPORTANT"
><TABLE
CLASS="IMPORTANT"
WIDTH="90%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="common/important.png"
HSPACE="5"
ALT="Important"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
><A
NAME="STRQ"
></A
></P
><P
>The <TT
CLASS="USERINPUT"
><B
>$' ... '</B
></TT
>
<A
HREF="quoting.html#QUOTINGREF"
>quoted</A
> string-expansion
construct is a mechanism that uses escaped octal or hex values
to assign ASCII characters to variables, e.g.,
<B
CLASS="COMMAND"
>quote=$'\042'</B
>.</P
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="EXAMPLE"
><HR><A
NAME="ESCAPED"
></A
><P
><B
>Example 5-2. Escaped Characters</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 #!/bin/bash
2 # escaped.sh: escaped characters
3
4 #############################################################
5 ### First, let's show some basic escaped-character usage. ###
6 #############################################################
7
8 # Escaping a newline.
9 # ------------------
10
11 echo ""
12
13 echo "This will print
14 as two lines."
15 # This will print
16 # as two lines.
17
18 echo "This will print \
19 as one line."
20 # This will print as one line.
21
22 echo; echo
23
24 echo "============="
25
26
27 echo "\v\v\v\v" # Prints \v\v\v\v literally.
28 # Use the -e option with 'echo' to print escaped characters.
29 echo "============="
30 echo "VERTICAL TABS"
31 echo -e "\v\v\v\v" # Prints 4 vertical tabs.
32 echo "=============="
33
34 echo "QUOTATION MARK"
35 echo -e "\042" # Prints " (quote, octal ASCII character 42).
36 echo "=============="
37
38
39
40 # The $'\X' construct makes the -e option unnecessary.
41
42 echo; echo "NEWLINE and (maybe) BEEP"
43 echo $'\n' # Newline.
44 echo $'\a' # Alert (beep).
45 # May only flash, not beep, depending on terminal.
46
47 # We have seen $'\nnn" string expansion, and now . . .
48
49 # =================================================================== #
50 # Version 2 of Bash introduced the $'\nnn' string expansion construct.
51 # =================================================================== #
52
53 echo "Introducing the \$\' ... \' string-expansion construct . . . "
54 echo ". . . featuring more quotation marks."
55
56 echo $'\t \042 \t' # Quote (") framed by tabs.
57 # Note that '\nnn' is an octal value.
58
59 # It also works with hexadecimal values, in an $'\xhhh' construct.
60 echo $'\t \x22 \t' # Quote (") framed by tabs.
61 # Thank you, Greg Keraunen, for pointing this out.
62 # Earlier Bash versions allowed '\x022'.
63
64 echo
65
66
67 # Assigning ASCII characters to a variable.
68 # ----------------------------------------
69 quote=$'\042' # " assigned to a variable.
70 echo "$quote Quoted string $quote and this lies outside the quotes."
71
72 echo
73
74 # Concatenating ASCII chars in a variable.
75 triple_underline=$'\137\137\137' # 137 is octal ASCII code for '_'.
76 echo "$triple_underline UNDERLINE $triple_underline"
77
78 echo
79
80 ABC=$'\101\102\103\010' # 101, 102, 103 are octal A, B, C.
81 echo $ABC
82
83 echo
84
85 escape=$'\033' # 033 is octal for escape.
86 echo "\"escape\" echoes as $escape"
87 # no visible output.
88
89 echo
90
91 exit 0</PRE
></TD
></TR
></TABLE
><HR></DIV
><P
>A more elaborate example:</P
><DIV
CLASS="EXAMPLE"
><HR><A
NAME="BASHEK"
></A
><P
><B
>Example 5-3. Detecting key-presses</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 #!/bin/bash
2 # Author: Sigurd Solaas, 20 Apr 2011
3 # Used in ABS Guide with permission.
4 # Requires version 4.2+ of Bash.
5
6 key="no value yet"
7 while true; do
8 clear
9 echo "Bash Extra Keys Demo. Keys to try:"
10 echo
11 echo "* Insert, Delete, Home, End, Page_Up and Page_Down"
12 echo "* The four arrow keys"
13 echo "* Tab, enter, escape, and space key"
14 echo "* The letter and number keys, etc."
15 echo
16 echo " d = show date/time"
17 echo " q = quit"
18 echo "================================"
19 echo
20
21 # Convert the separate home-key to home-key_num_7:
22 if [ "$key" = $'\x1b\x4f\x48' ]; then
23 key=$'\x1b\x5b\x31\x7e'
24 # Quoted string-expansion construct.
25 fi
26
27 # Convert the separate end-key to end-key_num_1.
28 if [ "$key" = $'\x1b\x4f\x46' ]; then
29 key=$'\x1b\x5b\x34\x7e'
30 fi
31
32 case "$key" in
33 $'\x1b\x5b\x32\x7e') # Insert
34 echo Insert Key
35 ;;
36 $'\x1b\x5b\x33\x7e') # Delete
37 echo Delete Key
38 ;;
39 $'\x1b\x5b\x31\x7e') # Home_key_num_7
40 echo Home Key
41 ;;
42 $'\x1b\x5b\x34\x7e') # End_key_num_1
43 echo End Key
44 ;;
45 $'\x1b\x5b\x35\x7e') # Page_Up
46 echo Page_Up
47 ;;
48 $'\x1b\x5b\x36\x7e') # Page_Down
49 echo Page_Down
50 ;;
51 $'\x1b\x5b\x41') # Up_arrow
52 echo Up arrow
53 ;;
54 $'\x1b\x5b\x42') # Down_arrow
55 echo Down arrow
56 ;;
57 $'\x1b\x5b\x43') # Right_arrow
58 echo Right arrow
59 ;;
60 $'\x1b\x5b\x44') # Left_arrow
61 echo Left arrow
62 ;;
63 $'\x09') # Tab
64 echo Tab Key
65 ;;
66 $'\x0a') # Enter
67 echo Enter Key
68 ;;
69 $'\x1b') # Escape
70 echo Escape Key
71 ;;
72 $'\x20') # Space
73 echo Space Key
74 ;;
75 d)
76 date
77 ;;
78 q)
79 echo Time to quit...
80 echo
81 exit 0
82 ;;
83 *)
84 echo You pressed: \'"$key"\'
85 ;;
86 esac
87
88 echo
89 echo "================================"
90
91 unset K1 K2 K3
92 read -s -N1 -p "Press a key: "
93 K1="$REPLY"
94 read -s -N2 -t 0.001
95 K2="$REPLY"
96 read -s -N1 -t 0.001
97 K3="$REPLY"
98 key="$K1$K2$K3"
99
100 done
101
102 exit $?</PRE
></TD
></TR
></TABLE
><HR></DIV
><P
>See also <A
HREF="bash2.html#EX77"
>Example 37-1</A
>.</P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\"</SPAN
></DT
><DD
><P
> gives the quote its literal meaning</P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 echo "Hello" # Hello
2 echo "\"Hello\" ... he said." # "Hello" ... he said.</PRE
></TD
></TR
></TABLE
></P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\$</SPAN
></DT
><DD
><P
>gives the dollar sign its literal meaning
(variable name following <SPAN
CLASS="TOKEN"
>\$</SPAN
> will not be
referenced)</P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 echo "\$variable01" # $variable01
2 echo "The book cost \$7.98." # The book cost $7.98.</PRE
></TD
></TR
></TABLE
></P
></DD
><DT
><SPAN
CLASS="TOKEN"
>\\</SPAN
></DT
><DD
><P
>gives the backslash its literal meaning</P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="90%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 echo "\\" # Results in \
2
3 # Whereas . . .
4
5 echo "\" # Invokes secondary prompt from the command-line.
6 # In a script, gives an error message.
7
8 # However . . .
9
10 echo '\' # Results in \</PRE
></TD
></TR
></TABLE
></P
></DD
></DL
></DIV
><DIV
CLASS="NOTE"
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="common/note.png"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>The behavior of <SPAN
CLASS="TOKEN"
>\</SPAN
> depends on whether
it is escaped, <A
HREF="variables.html#SNGLQUO"
>strong-quoted</A
>,
<A
HREF="variables.html#DBLQUO"
>weak-quoted</A
>, or appearing within
<A
HREF="commandsub.html#COMMANDSUBREF"
>command substitution</A
> or a
<A
HREF="here-docs.html#HEREDOCREF"
>here document</A
>.
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 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 Stphane Chazelas.</PRE
></TD
></TR
></TABLE
>
</P
><P
>Elements of a string assigned to a variable may be escaped, but
the escape character alone may not be assigned to a variable.
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 variable=\
2 echo "$variable"
3 # Will not work - gives an error message:
4 # test.sh: : command not found
5 # A "naked" escape cannot safely be assigned to a variable.
6 #
7 # What actually happens here is that the "\" escapes the newline and
8 #+ the effect is variable=echo "$variable"
9 #+ invalid variable assignment
10
11 variable=\
12 23skidoo
13 echo "$variable" # 23skidoo
14 # This works, since the second line
15 #+ is a valid variable assignment.
16
17 variable=\
18 # \^ escape followed by space
19 echo "$variable" # space
20
21 variable=\\
22 echo "$variable" # \
23
24 variable=\\\
25 echo "$variable"
26 # Will not work - gives an error message:
27 # test.sh: \: command not found
28 #
29 # First escape escapes second one, but the third one is left "naked",
30 #+ with same result as first instance, above.
31
32 variable=\\\\
33 echo "$variable" # \\
34 # Second and fourth escapes escaped.
35 # This is o.k.</PRE
></TD
></TR
></TABLE
>
</P
></TD
></TR
></TABLE
></DIV
><P
>Escaping a space can prevent word splitting in a command's argument list.
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 file_list="/bin/cat /bin/gzip /bin/more /usr/bin/less /usr/bin/emacs-20.7"
2 # List of files as argument(s) to a command.
3
4 # Add two files to the list, and list all.
5 ls -l /usr/X11R6/bin/xsetroot /sbin/dump $file_list
6
7 echo "-------------------------------------------------------------------------"
8
9 # What happens if we escape a couple of spaces?
10 ls -l /usr/X11R6/bin/xsetroot\ /sbin/dump\ $file_list
11 # Error: the first three files concatenated into a single argument to 'ls -l'
12 # because the two escaped spaces prevent argument (word) splitting.</PRE
></TD
></TR
></TABLE
></P
><P
><A
NAME="ESCNEWLINE"
></A
></P
><P
>The <SPAN
CLASS="TOKEN"
>escape</SPAN
> also provides a means of writing a
multi-line command. Normally, each separate line constitutes
a different command, but an <SPAN
CLASS="TOKEN"
>escape</SPAN
> at the end
of a line <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>escapes the newline character</I
></SPAN
>,
and the command sequence continues on to the next line.</P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 (cd /source/directory && tar cf - . ) | \
2 (cd /dest/directory && tar xpvf -)
3 # Repeating Alan Cox's directory tree copy command,
4 # but split into two lines for increased legibility.
5
6 # As an alternative:
7 tar cf - -C /source/directory . |
8 tar xpvf - -C /dest/directory
9 # See note below.
10 # (Thanks, Stphane Chazelas.)</PRE
></TD
></TR
></TABLE
>
<DIV
CLASS="NOTE"
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="common/note.png"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>If a script line ends with a <SPAN
CLASS="TOKEN"
>|</SPAN
>, a pipe
character, then a <SPAN
CLASS="TOKEN"
>\</SPAN
>, an escape, is not strictly
necessary. It is, however, good programming practice to always
escape the end of a line of code that continues to the
following line.</P
></TD
></TR
></TABLE
></DIV
></P
><P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
> 1 echo "foo
2 bar"
3 #foo
4 #bar
5
6 echo
7
8 echo 'foo
9 bar' # No difference yet.
10 #foo
11 #bar
12
13 echo
14
15 echo foo\
16 bar # Newline escaped.
17 #foobar
18
19 echo
20
21 echo "foo\
22 bar" # Same here, as \ still interpreted as escape within weak quotes.
23 #foobar
24
25 echo
26
27 echo 'foo\
28 bar' # Escape character \ taken literally because of strong quoting.
29 #foo\
30 #bar
31
32 # Examples suggested by Stphane Chazelas.</PRE
></TD
></TR
></TABLE
></P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="quoting.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="exit-status.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Quoting</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="quoting.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Exit and Exit Status</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|