在bash循环参数列表中注释

Chr*_*son 4 syntax bash comments loops indentation

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

cod*_*ter 6

您可以将值存储在数组中,然后循环遍历它们.与行继续不同,数组初始化可以散布注释.

values=(
    arg1 arg2     # handle library
    other1 other2 # handle binary
    win1 win2     # Special windows things
)
for i in "${values[@]}"; do
    ...
done
Run Code Online (Sandbox Code Playgroud)

另一种尽管效率较低的方法是使用命令替换.这种方法容易出现单词分裂和通配问题.

for i in $(
        echo arg1 arg2     # handle library
        echo other1 other2 # handle binary
        echo win1 win2     # Special windows things
); do
  ...
done
Run Code Online (Sandbox Code Playgroud)

有关: