bash 命令跨越多行,中间有几行注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12813987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash command spanning multiple lines with several lines of comments in-between
提问by Xu Wang
Possible Duplicate:
Bash: How to Put Line Comment for a Multi-line Command
可能的重复:
Bash:如何为多行命令添加行注释
I would like to do something like this
我想做这样的事情
sudo apt-get install \
#a very long description
#of the package
#that spans multiple lines
pkg1 \ #maybe I want an inline comment also
#another description that
#spans multiple lines
pkg2
Note that I'm not just interested in the apt-get
command.
请注意,我不仅对apt-get
命令感兴趣。
回答by phininity
As far as I know Bash ignores everything after the '#' in a single command, and multilining won't change that. However you can probably achieve the same level of expression using bash arrays:
据我所知,Bash 在单个命令中忽略 '#' 之后的所有内容,并且多行不会改变这一点。但是,您可能可以使用 bash 数组实现相同级别的表达:
packagelist=(
package1 # Inline Comments
# Multiline Comments too
package2
# Package description goes here
# Detailed descriptions..
)
sudo apt-get install ${packagelist[@]}