title: how to check if a file exist using adb shell
body: <p>I have a bash script which goes as follows </p>
  
  <pre><code>if [ -f "/sdcard/testfile"]
  then 
  echo "exists" &gt; /sdcard/outfile
  else
  echo "does not exist" &gt; /sdcard/outfile
  fi
  </code></pre>
  
  <p>I have sufficient permission to run this with <code>/system/bin/sh</code>.
  I am calling this script from my application and running this with <code>/system/bin/sh</code>.
  But after running I am getting false, even if the file '/sdcard/testfile' is there.
  When I am explicitly running in adb shell, I am getting this error </p>
  
  <pre><code>[: not found
  </code></pre>
  
  <p>Is there any other way to accomplish this task? I cannot just use java.io.File because of permission issue of application; therefore, I am adhering to shell script (command).</p>
  
  <p>I need the output in the application itself. I mean, </p>
  
  <pre><code>if(filesAreAvailable)
      executeSomething();
  else
      executeSomethingElse();
  </code></pre>
  
  <p>Basically I am programmatically writing this script in the <code>/data/data/myPackageName/files</code> directory and for calling the command:</p>
  
  <pre><code>if [ -f "/sdcard/testfile"]
  </code></pre>
  
  <p>as</p>
  
  <pre><code>fileWriterScript.write("if [ -f \"/sdcard/testfile\" ]\n")
  </code></pre>