passing strings to while loop passing strings to while loop shell shell

passing strings to while loop


< redirection operator only works with files. for your requirement use a for loop

#!/bin/bashfor x in "var1" "var2"do   echo $xdone


To pass string to your while loop, you need to use herestring <<< notation.

$ while read line; do     echo "$line"done <<< "This is my test line"This is my test line


printf "%s\n" "var1" "var2" |while read linedo      echo "successful: $line"done

The printf command echoes each argument on a line on its own.