How to write Shell script comments
This article introduces the knowledge of "how to write Shell script comments". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. radio comments
Lines that begin with "#" are comments and are ignored by the interpreter.
The code is as follows:
#-
# this is an auto-typing ipa script based on webfrogs's ipa-build writing:
# https://github.com/webfrogs/xcode_shell/blob/master/ipa-build
# function: automatically package etao ios app and produce ipa packages from 14 channels
# Features: automatic packaging without entering any parameters
#-
# user configuration area starts #
#
#
# Project root directory. It is recommended to put this script in the project root directory, so there is no need to change it here.
# App name, make sure it matches the target_name.app name under Product in Xcode
#
# end of user configuration area #
II. Multiline comments
What if you encounter a large piece of code that needs to be commented temporarily and uncommented later in the development process? It is too hard to add a # symbol to each line. You can enclose the code to be commented in a pair of curly braces and define it as a function. If there is no place to call this function, the code will not be executed, achieving the same effect as the comment. Example:
The code is as follows:
NotExce () {
Cp. / a.txt. / b.txt
Mkdir-p {1Pert 2jue 3} / {4jre 5pr 6}
Echo "ok"
}
But if we need to comment on a large piece of shell script, if we all add # in front of each line, which is really not a very comfortable thing for us, then, in shell, is there any way to use c-language comments / *. * / to achieve the effect of a whole paragraph of comments? The notes have been tested and found that the following method is ok.
The code is as follows:
You can even turn the whole shell to be annotated into a function to prevent execution Such as example 2.
There are other ways to comment out multiple lines of shell:
The first is based on Here Documents and: implementation, similar to example 3
If there are backquotes in the annotated content, an error will be reported.
The code is as follows:
: