2007年7月18日 星期三

想要在 bash 裡面把ㄧ個 group 的資料註解掉該怎麼做

想要在 bash 裡面把ㄧ個 group 的資料註解掉該怎麼做

範例
true << bt_encry
This is comments, Hello, Hello....
bt_encry

another format as following example.
: << COMMENTBLOCK
echo "This line will not echo."
This is a comment line missing the "#" prefix.
This is another comment line missing the "#" prefix.
&*@!!++=
The above line will cause no error message,
because the Bash interpreter will ignore it.
COMMENTBLOCK

Reference the following technique which was called "Here Document".
Example 17-10. Commenting out a block of code

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
17
18 # The above technique also comes in useful for commenting out
19 #+ a block of working code for debugging purposes.
20 # This saves having to put a "#" at the beginning of each line,
21 #+ then having to go back and delete each "#" later.
22
23 : << DEBUGXXX
24 for file in *
25 do
26 cat "$file"
27 done
28 DEBUGXXX
29
30 exit 0

沒有留言: