相关疑难解决方法(0)

如何为多行命令添加行注释

我知道如何在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 shell comments

303
推荐指数
4
解决办法
6万
查看次数

对Bash的内联评论?

我希望能够在一行命令中注释掉一个标志.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)

bash comments

133
推荐指数
4
解决办法
17万
查看次数

用反斜杠分隔行时是否可以使用注释?

我想像这样嵌入评论

ls -l \
-a \
# comment here
-h \
-t . 
Run Code Online (Sandbox Code Playgroud)

但这似乎是不可能的。也许存在其他变体?将评论放在反斜杠之后或以反斜杠结束评论无济于事。

bash shell sh

7
推荐指数
3
解决办法
649
查看次数

在bash循环参数列表中注释

我想评论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)

syntax bash comments loops indentation

4
推荐指数
1
解决办法
163
查看次数

是否可以在 shell 脚本的多行命令中包含内联注释?

我知道我可以在 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或类似,我也很感兴趣。

bash shell

0
推荐指数
1
解决办法
50
查看次数

标签 统计

bash ×5

comments ×3

shell ×3

indentation ×1

loops ×1

sh ×1

syntax ×1