title: How do I use the output of an ls command in an if statement in a bash shell
body: <p>I want to check if only one instance of a file exists before going on to process that file.</p>
  
  <p>I can check how many instances exist using this command: </p>
  
  <pre><code>ls -l $INPUT_DIR/${INPUT_FILE_PREFIX}cons*.csv.gz | wc -l;
  </code></pre>
  
  <p>However, when I go to use this within an if statement, I am warned that the <code>ls: command not found</code>.</p>
  
  <pre><code>if [ls -l $INPUT_DIR/${INPUT_FILE_PREFIX}cons*.csv.gz | wc -l = '1']
   then
   echo "Only 1 File Exists";
  fi
  </code></pre>
  
  <p>I've tried adding a semicolon at the end of the ls command and enclosing it in square brackets - neither of these yielded any results.</p>
  
  <p>I very rarely have to do any Shell scripting, and I suspect this a very basic error, so any help would be much appreciated.</p>