1, the simplest way
Copy Code code as follows:
: <<block
.... Comment Content
Block
The input is redefined to the previous command, but: it is an empty command, so it is equivalent to a comment.
If a command with an inverted quotation mark is an error in the annotation, the inverted quotation marks are not commented out, for example, var= ' ls-l ' will not be commented out.
2, solve the problem of the comments have inverted quotes
A, method one
Copy Code code as follows:
: <<block '
.... Comment Content
' Block
B, Method two
Copy Code code as follows:
:<< ' Block
.... Comment Content
Block '
C, Method Three
Copy Code code as follows:
:<< '
.... Comment Content
'
Block for here Documents in the definition of the symbol, the name of any, as long as the match before and after the line.
3.: Instructions and here Documents
: Is not doing anything (do nothing) that is empty command, generally used in if...then ... In a condition, as a command to do nothing, such as:
Copy Code code as follows:
If [-D $DIRECTORY]; Then
:
Else
Echo ' Directory does not exit! '
Fi
The following example:
Copy Code code as follows:
Cmd<<word
Any input
File content
Word
Is the use of here Documents, meaning to pass the above definition Word to a script or command.
Word's content is to enter anything between two words, so that you can use CMD in the script to perform the input without rebuilding a file.
Here Documents are commonly used in menu screens, such as:
Copy Code code as follows:
Cat <<menu
1.List
2.Help
3.Exit
Menu
As for
Copy Code code as follows:
: <<word
.... Comment Content
Word
It's similar to building a local file and then executing an empty command on it, doing nothing, which is equivalent to commenting.
Add:
The code is as follows:
Copy Code code as follows:
for ((i=0; i<10; i++))
Todo
: <<_a_
if []; Then
...
Fi
_a_
echo ""
Done
Above: <<_a_ and _a_ represent segment annotation, you can comment out the middle code
_a_ is the definition symbol in here Documents, the name is arbitrary, as long as the match on the line
: Empty command, which is equivalent to doing nothing (doing anything) is an empty command, generally used in if...then ... In a condition, as a command to do nothing, such as:
Copy Code code as follows:
If [-D $DIRECTORY]; Then
:
Else
Echo ' Directory does not exit! '
Fi
If a command with an inverted quotation mark is an error in the annotation, the inverted quotation marks are not commented out, for example, var= ' ls-l ' will not be commented out.
Troubleshoot problems with inverted quotes in comments
Copy Code code as follows:
: <<_a_ '
.... Comment Content
' _a_
A single line will not be said, the well number # can be done. Here are a few lines.
A. Through here documents to achieve:
1)
: <<eof
The code for the annotation ...
Eof
Colon: means doing nothing.
Description: When a variable reference or inverted quotation mark appears in the annotation code, bash tries to parse them and prompts for an error message. There are several ways to fix this:
1.
Copy Code code as follows:
: <<\eof
The code for the annotation ...
Eof
2.
Copy Code code as follows:
:<< ' EOF '
The code for the annotation ...
Eof
3.
Copy Code code as follows:
:<< ' EOF
The code for the annotation ...
EOF '
4.
Copy Code code as follows:
: <<eof '
The code for the annotation ...
' EOF
5.
Copy Code code as follows:
:<< '
The code for the annotation ...
'