Shell Multiline Comment

Source: Internet
Author: User

Because the shell does not support direct multiline annotations, it summarizes the following workarounds for multiple lines of shell annotations one, through here documents and: Realize 1, the simplest method: <<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 quote in the comment is an error.  The inverted quote part is not commented out, for example, ab= ' ls-l ABC ' will not be commented out. 2, solve the annotation in the question of inverted quotes A, method one: <<block ' .... Annotation Content     ' Block B, method two:<< ' block .... Annotation content block ' C, method three:<< '     .... Annotation content     ' above three kinds of methods are through in the:< block for here documents in the definition of the symbol can be arbitrarily named, as long as the match before and after the line of 3, simply said: instructions and here documents: what is also does not make (does nothing) is the empty command. Its most basic function is in the if,then condition.  The parts of an if statement must be executed, but sometimes you don't care if the condition is true (or false) and only cares about the opposite. For example, if you detect that there is a path and do nothing, there is no echo error.  Can be written as if [-D $DIRECTORY];   Then: #do Nothing eles echo "The directory does not exit " fi below example command<<word any input file content Word is here for documents, meaning that the above definition (word, also interpreted as local document name) is passed to a script or command, and Word enters anything from two word (word is here).  The definitions in documents can be named at will, as long as they are matched, so that you can use command in the script to execute the input without rebuilding a file. Commonly used in menu screens, for example: Cat <<menu 1. List files 2.HELP 3.exit Menu: <<word .... NoteInterpreting content Word is similar to building a local file, and then executing an empty command on it, which is doing nothing, is equivalent to commenting. More detailed here document description can refer to http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/here-docs.html two, through the loop implementation 1,   While and: Implementing While:do break Annotation content done 2, until and: implementing until: annotation content done note whether the annotation content contains "done", including the unexpected end of the loop three, other methods 1, method one :: | |:<<\comments    .....  Annotation content       COMMENTS Master said this method is best, because here the documents will not be executed, will only be analyzed, should not be the second: the actual IO redirect.  2, method Two: << ' block ' can be the inside of the variable extension closed off. For example::~> a=b:~> Cat <<end > This are \ $A: $A > End this are $A: B:~> cat << ' End ' > thi S. \ $A: $A > End this is \ $A: $A 3, method three: | | {  .... Comment Content} This method does not need to come here Documents, but this method should pay attention to the contents of the comment 4, method four:<<\eof    .... Comment Content     EOF The above method can be used to turn off the extension in here documents, any characters before ending marker in here-document are actually using <<\eof < < ' EOF ', even <<<\eof more concise on the grammar. But this approach also needs to pay attention to the EOF in the annotation content

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.