Debian Codegraph @

escaped.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/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 echoscip-shell system . . echo. ""
12
13 echoscip-shell system . . echo. "This will print
14 as two lines."
15 # This will print
16 # as two lines.
17
18 echoscip-shell system . . echo. "This will print \
19 as one line."
20 # This will print as one line.
21
22 echoscip-shell system . . echo.; echoscip-shell system . . echo.
23
24 echoscip-shell system . . echo. "============="
25
26
27 echoscip-shell system . . echo. "\v\v\v\v" # Prints \v\v\v\v literally.
28 # Use the -e option with 'echo' to print escaped characters.
29 echoscip-shell system . . echo. "============="
30 echoscip-shell system . . echo. "VERTICAL TABS"
31 echoscip-shell system . . echo. -e "\v\v\v\v" # Prints 4 vertical tabs.
32 echoscip-shell system . . echo. "=============="
33
34 echoscip-shell system . . echo. "QUOTATION MARK"
35 echoscip-shell system . . echo. -e "\042" # Prints " (quote, octal ASCII character 42).
36 echoscip-shell system . . echo. "=============="
37
38
39
40 # The $'\X' construct makes the -e option unnecessary.
41
42 echoscip-shell system . . echo.; echoscip-shell system . . echo. "NEWLINE and (maybe) BEEP"
43 echoscip-shell system . . echo. $'\n' # Newline.
44 echoscip-shell system . . 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 echoscip-shell system . . echo. "Introducing the \$\' ... \' string-expansion construct . . . "
54 echoscip-shell system . . echo. ". . . featuring more quotation marks."
55
56 echoscip-shell system . . 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 echoscip-shell system . . 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 echoscip-shell system . . echo.
65
66
67 # Assigning ASCII characters to a variable.
68 # ----------------------------------------
69 quote=$'\042' # " assigned to a variable.
70 echoscip-shell system . . echo. "$quote Quoted string $quote and this lies outside the quotes."
71
72 echoscip-shell system . . echo.
73
74 # Concatenating ASCII chars in a variable.
75 triple_underline=$'\137\137\137' # 137 is octal ASCII code for '_'.
76 echoscip-shell system . . echo. "$triple_underline UNDERLINE $triple_underline"
77
78 echoscip-shell system . . echo.
79
80 ABC=$'\101\102\103\010' # 101, 102, 103 are octal A, B, C.
81 echoscip-shell system . . echo. $ABC
82
83 echoscip-shell system . . echo.
84
85 escape=$'\033' # 033 is octal for escape.
86 echoscip-shell system . . echo. "\"escape\" echoes as $escape"
87 # no visible output.
88
89 echoscip-shell system . . echo.
90
91 exit 0