title: Bash RegEx to check floating point numbers from user input
body: <p>I'm relatively new to bash programming and i am currently creating a simple calculator.</p>
  
  <p>It needs to use floating point numbers and check they are so.</p>
  
  <p>I have a checkNumbers function:</p>
  
  <pre><code>function checkNumber {
  
      regExp=[0-9]
  
      if [ $testNo =~ $regExp ]
      then
          echo "That is a number!"
          let check=1
      else
          echo "Damn! Not A Number!"
      fi
  }
  </code></pre>
  
  <p>where i get the user to input a number like this:</p>
  
  <pre><code>while [ $check -eq 0]
  do
      echo "Please enter a number
      read testNo
      echo ""
      checkNumber
  done
  </code></pre>
  
  <p>This does not work, i get this error:</p>
  
  <blockquote>
    <p>./calculator.sh: line 39: [: =~: binary operator expected</p>
  </blockquote>
  
  <p>line 39 is:</p>
  
  <pre><code>if [ $testNo =~ $regExp ] 
  </code></pre>
  
  <p>I have tried lots of Regular Expressions like:</p>
  
  <pre><code>^*[0-9]*$
  </code></pre>
  
  <p>and</p>
  
  <pre><code>^*[0-9]\.[0.9]*$
  </code></pre>
  
  <p>etc etc.</p>
  
  <p>also, i have tied other ways of performing the check:</p>
  
  <pre><code>case $testNo
  in
      ^*[0-9]*$) echo "That is a number!";;
      *) echo "Error! Not a number!";;
  esac
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if [ $testNo = ^*[0-9]*$ ]
  then
      echo "etc etc"
  else
      echo "oops"
  fi
  </code></pre>
  
  <p>I also need this to work with floating point numbers.</p>
  
  <p>could someone please let me know how i go about this? </p>