Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash循环参数列表中的注释_Bash_Loops_Syntax_Comments_Indentation - Fatal编程技术网

bash循环参数列表中的注释

bash循环参数列表中的注释,bash,loops,syntax,comments,indentation,Bash,Loops,Syntax,Comments,Indentation,我想对bash for循环参数列表的部分内容进行注释。我想写这样的东西,但我不能在多行之间打破循环。使用\似乎也不起作用 for i in arg1 arg2 # Handle library other1 other2 # Handle binary win1 win2 # Special windows things do .... done; 您可以将值存储在数组中,然后循环遍历它们。数组初始化可以插入注释,这与行继续不同 values=( arg1

我想对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
另一种方法是使用命令替换,尽管效率较低。这种方法容易出现问题


相关的:


在下面的代码中,我不使用
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

您应该能够使用\来转义换行符。只需确保它后面没有尾随空格,否则就是在逃逸一个空格。但是,您将无法像使用codeforester的解决方案那样对参数进行注释。@jason:注释内部不起作用,我很抱歉afraid@codeforester,我将您的编辑回滚到问题标题,它与问题的实际内容或答案不一致。这有分词和全局问题,就像我的第二个解决方案一样。
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