I want to comment parts of a bash for loop argument list. I would like to write something like this, but I can't break the loop across multiple lines. Using \
doesn't seem to work either.
for i in
arg1 arg2 # Handle library
other1 other2 # Handle binary
win1 win2 # Special windows things
do .... done;
You can store your values in an array and then loop through them. The array initialization can be interspersed with comments unlike line continuation.
values=(
arg1 arg2 # handle library
other1 other2 # handle binary
win1 win2 # Special windows things
)
for i in "${values[@]}"; do
...
done
Another, albeit less efficient, way of doing this is to use command substitution. This approach is prone to word splitting and globbing issues.
for i in $(
echo arg1 arg2 # handle library
echo other1 other2 # handle binary
echo win1 win2 # Special windows things
); do
...
done
Related:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With