bash循环参数列表中的注释
我想对bash for循环参数列表的部分内容进行注释。我想写这样的东西,但我不能在多行之间打破循环。使用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
\
似乎也不起作用
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