Bash script to create variables from and run commands on each item in an external list

Solution 1:

You can try this:

while read
do
  read dir
  read ip
  # Your command using $dir and $ip
done < list.txt

The read after while reads the comments and discards them.

Each read command reads a single line from standard input (which in this case we've redirected from list.txt). For a more detailed explanation, see the documentation.