繁体   English   中英

在bash循环参数列表中注释

[英]Comment in a bash loop argument list

我想评论bash for循环参数列表的部分内容。 我想写这样的东西,但我不能打破多行的循环。 使用\\似乎也不起作用。

for i in
  arg1 arg2     # Handle library
  other1 other2 # Handle binary
  win1 win2     # Special windows things
do .... done;

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

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

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

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

有关:

在下面的代码我不使用handlethings+= ,忘记空间太容易了。

handlethings="arg1 arg2"                     # Handle library
handlethings="${handlethings} other1 other2" # Handle binary
handlethings="${handlethings} win1 win2"     # Special windows things

for i in ${handlethings}; do
   echo "i=$i"
done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM