title: While file exists in bash
body: <p>Pretty much it checks if the file 'ok.temp' exists. If it doesn't it goes into a loop of sleeping for 2 seconds before checking again. After the file is deemed that it exists it continues on. </p>
  
  <p>Unfortunately I'm getting the errors stated below the following code:</p>
  
  <pre><code>#!/bin/sh
  # Read the sensor values
  if [ ! -f saved.txt ]
  then
      touch saved.txt
  fi 
  
  #saved values count
  sCount=0
  
  #value aggregates
  vTTemp=0
  vTHumid=0
  vTLux=0
  
  #previous aggregates
  pTTemp=0
  pTHumid=0
  pTLux=0
  
  while : 
  do
  vTemp=0
  vHumid=0
  vLux=0
  
  if [ $sCount -gt 0 ] 
  then
      if [ $(( $sCount % 5 )) -eq 0 ]
      then
          #set previous aggregates as current
          pTTemp=$vTTemp
          pTHumid=$vTHumid
          pTLux=$vTLux
  
          #reset current aggregates
          vTTemp=0
          vTHumid=0
          vTLux=0
      fi
  fi
  
      while [ ! –f ok.temp ]
      do
          sleep 20
      done
  
      if [ -f logfile.txt ]
      then
          rResult=`tail -1 logfile.txt`
          rSaved=`tail -1 saved.txt`
          if [ $rResult -eq $rSaved ]
          then
              vTemp=`echo $rResult | cut -d" " -f1`
              vHumid=`echo $rResult | cut -d" " -f2`
              vLux=`echo $rResult | cut -d" " -f3`
              echo $rResult &gt;&gt; saved.txt
  
              # aggregate results
              vTTemp=`expr $vTTemp + $vTemp`
              vTHumid=`expr $vTHumid + $vHumid`
              vTLux=`expr $vTLux + $vLux`
              echo 'Most recent results recieved from sensor has been saved'
          else
              echo 'Most recent result has already been saved, skipping'
          fi
      fi
  
      echo '[Previous] Temp:'$pTTemp' Humid:'$pTHumid' Lux:'$pTLux
      echo '[Current] Temp:'$vTTemp' Humid:'$vTHumid' Lux:'$vTLux
  
      sCount=`expr $sCount + 1`
  done
  </code></pre>
  
  <p>And I'm getting these errors:</p>
  
  <p>Line 43 = while [ ! –f ok.temp ]</p>
  
  <pre><code>line 43: [: f: unary operator expected
  </code></pre>
  
  <p>Line 52 = if [ $rResult -eq $rSaved ]</p>
  
  <pre><code>line 52: [: too many arguments
  </code></pre>
  
  <p>Any help would be greatly appreciated :)</p>