title: Loop over set of strings containing spaces
body: <p>I have multiple strings like "a b", "c d", "foo bar" and so on. I want to loop over this set of string and perform an action on each of these. In this action I call multiple other scripts so I do not want to change IFS for this loop since it could break my invocation of other scripts. This is why I try to escape the spaces contained in these strings but without success. </p>
  
  <p>So for instance I expect to get</p>
  
  <pre><code>a b
  c d
  </code></pre>
  
  <p>And I tried the following:</p>
  
  <pre><code>#!/bin/sh
  
  x="a b"
  y="c d"
  
  echo "Attempt 1"
  all="$x $y"
  
  for i in $all ; do
    echo $i
  done
  
  echo "Attempt 2"
  all="a\ b c\ d"
  for i in $all ; do
    echo $i
  done
  
  echo "Attempt 3"
  all=($x $y)
  for i in ${all[@]} ; do
    echo $i
  done
  
  echo "Attempt 4"
  all='"'$x'" "'$y'"'
  for i in $all ; do
    echo $i
  done
  
  echo "Attempt 5"
  for i in "$x" "$y" ; do
    echo $i
  done
  
  echo "Attempt 6"
  all2=("a b" "c d");
  for i in ${all2[@]}; do
    echo $i
  done
  
  echo "Attempt 7"
  all3="a b c d"
  echo $all3|
  while read i; do
    echo $i 
  done 
  </code></pre>
  
  <p>Only attempt 5 succeeds, but I would like to <em>do this without having to declare one variable per string</em>, (it would be painful to maintain). I just introduced x and y for testing but the idea is to declare in one variable the set "a b" and "c d".</p>