title: bash: stop a for loop if the internal command exits with non-zero code
body: <p>I have this code:</p>
  
  <pre><code>for x in 1 2 3;
  do
    ./test.sh $x
  done
  </code></pre>
  
  <p>test.sh looks like this</p>
  
  <pre><code>echo "$1"
  if [ "$1" = "2" ]
  then
    exit 1
  else
    exit 0
  fi
  </code></pre>
  
  <p>how do I get it to output only </p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>Instead of </p>
  
  <pre><code>1
  2
  3
  </code></pre>