簡體   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