Debian Codegraph @

commentblock.sh

raw symbols SCIP
1 #!/bin/bash
2 # commentblock.sh
3
4 : <<COMMENTBLOCK
5 echo "This line will not echo."
6 This is a comment line missing the "#" prefix.
7 This is another comment line missing the "#" prefix.
8
9 &*@!!++=
10 The above line will cause no error message,
11 because the Bash interpreter will ignore it.
12 COMMENTBLOCK
13
14 echo "Exit value of above \"COMMENTBLOCK\" is $?." # 0
15 # No error shown.
16 echo
17
18
19 # The above technique also comes in useful for commenting out
20 #+ a block of working code for debugging purposes.
21 # This saves having to put a "#" at the beginning of each line,
22 #+ then having to go back and delete each "#" later.
23 # Note that the use of of colon, above, is optional.
24
25 echo "Just before commented-out code block."
26 # The lines of code between the double-dashed lines will not execute.
27 # ===================================================================
28 : <<DEBUGXXX
29 for file in *
30 do
31 cat "$file"
32 done
33 DEBUGXXX
34 # ===================================================================
35 echo "Just after commented-out code block."
36
37 exit 0
38
39
40
41 ######################################################################
42 # Note, however, that if a bracketed variable is contained within
43 #+ the commented-out code block,
44 #+ then this could cause problems.
45 # for example:
46
47
48 #/!/bin/bash
49
50 : <<COMMENTBLOCK
51 echo "This line will not echo."
52 &*@!!++=
53 ${foo_bar_bazz?}
54 $(rm -rf /tmp/foobar/)
55 $(touch my_build_directory/cups/Makefile)
56 COMMENTBLOCK
57
58
59 $ sh commented-bad.sh
60 commented-bad.sh: line 3: foo_bar_bazz: parameter null or not set
61
62 # The remedy for this is to strong-quote the 'COMMENTBLOCK' in line 49, above.
63
64 : <<'COMMENTBLOCK'
65
66 # Thank you, Kurt Pfeifle, for pointing this out.