是否可以在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'

如果可以使用zsh pwsh或类似,我也很感兴趣。

回答

不是直接的,但您可以将参数存储在多行定义的数组中,并且可以在这些行之间添加注释。

wget_args=(
  # 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'
)
wget "${wget_args[@]}"


以上是是否可以在shell脚本的多行命令中包含内联注释?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>