我知道如何在Bash脚本中编写多行命令,但是如何在多行命令中为每一行添加注释?
CommandName InputFiles \ # This is the comment for the 1st line
--option1 arg1 \ # This is the comment for the 2nd line
--option2 arg2 # This is the comment for the 3nd line
Run Code Online (Sandbox Code Playgroud)
但不幸的是,继续角色之后的评论\将打破命令.
我希望能够在一行命令中注释掉一个标志.Bash似乎只有from # till end-of-line评论.我正在看这样的技巧:
ls -l $([ ] && -F is turned off) -a /etc
Run Code Online (Sandbox Code Playgroud)
它很难看,但总比没有好.有没有更好的办法?
以下似乎有效,但我不确定它是否可移植:
ls -l `# -F is turned off` -a /etc
Run Code Online (Sandbox Code Playgroud) 我想像这样嵌入评论
ls -l \
-a \
# comment here
-h \
-t .
Run Code Online (Sandbox Code Playgroud)
但这似乎是不可能的。也许存在其他变体?将评论放在反斜杠之后或以反斜杠结束评论无济于事。
我想评论bash for循环参数列表的部分内容.我想写这样的东西,但我无法打破多行的循环.使用\似乎也不起作用.
for i in
arg1 arg2 # Handle library
other1 other2 # Handle binary
win1 win2 # Special windows things
do .... done;
Run Code Online (Sandbox Code Playgroud) 我知道我可以在 bash 中使用分隔长命令\- 有没有办法编写内联注释?
例如,类似于:
wget \
# Needed to get to end of around 100 pages of results
--level=0 \
# Save into downloads directory
--directory=downloads \
--recursive \
# Normally wget won't span hosts, and .example.com use a CDN
--span-hosts --domains='assets.publishing.example.com,www.example.com' \
# Only care about links matching this regex
--accept-regex 'assets|swag' --regex-type pcre
# The site we actually want to scrape
'https://www.example.com/swag'
Run Code Online (Sandbox Code Playgroud)
如果可以使用zsh pwsh或类似,我也很感兴趣。