title: If does not work in bash
body: <p>The script:</p>
  
  <pre><code>#!/bin/bash
  
  FILES=/home/admin/test/temp/*
  
  for f in $FILES
  do
          echo "Working on: $f"
          query=$(cat $f)
          /usr/bin/mysql -h $1  -u admin -pwpasswd -e "$query"
          echo "$?"
          if [ $? -eq 0 ];
          then
          echo "Successfully uploaded. Deleting file $f"
          rm $f
          else
          echo "breaking..."
          break
          fi
  done
  </code></pre>
  
  <p>the output:</p>
  
  <blockquote>
    <p>Working on: /home/admin/test/temp/temp_2014-08-01_02-40.txt ERROR 2003
    (HY000): Can't connect to MySQL server on '192.168.1.103' (110) 1
    Successfully uploaded. Deleting file
    /home/admin/test/temp/temp_2014-08-01_02-40.txt</p>
  </blockquote>
  
  <p>According to the $? value which is 1, it should break the loop, but it does not.</p>
  
  <p>Can somebody tell me what is the problem with it?</p>