How do I pass a list to for in bash?
I tried
echo "some
different
lines
" | for i ; do 
  echo do something with $i; 
done
but that doesn't work. I also tried to find an explanation with man but there is no man for
I know, I could use while instead, but I think I once saw a solution with for where they didn't define the variable but could use it inside the loop
for iterates over a list of words, like this:
for i in word1 word2 word3; do echo "$i"; done
use a while read loop to iterate over lines:
echo "some
different
lines" | while read -r line; do echo "$line"; done
Here is some useful reading on reading lines in bash.
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