title: Check if passed argument is file or directory in Bash
body: <p>I'm trying to write an extremely simple script in Ubuntu which would allow me to pass it either a filename or a directory, and be able to do something specific when it's a file, and something else when it's a directory.  The problem I'm having is when the directory name, or probably files too, has spaces or other escapable characters are in the name.</p>
  
  <p>Here's my basic code down below, and a couple tests.</p>
  
  <pre><code>#!/bin/bash
  
  PASSED=$1
  
  if [ -d "${PASSED}" ] ; then
      echo "$PASSED is a directory";
  else
      if [ -f "${PASSED}" ]; then
          echo "${PASSED} is a file";
      else
          echo "${PASSED} is not valid";
          exit 1
      fi
  fi
  </code></pre>
  
  <p>And here's the output:</p>
  
  <pre><code>andy@server~ $ ./scripts/testmove.sh /home/andy/
  /home/andy/ is a directory
  
  andy@server~ $ ./scripts/testmove.sh /home/andy/blah.txt
  /home/andy/blah.txt is a file
  
  andy@server~ $ ./scripts/testmove.sh /home/andy/blah\ with\ a\ space.txt
  /home/andy/blah with a space.txt is not valid
  
  andy@server~ $ ./scripts/testmove.sh /home/andy\ with\ a\ space/
  /home/andy with a space/ is not valid
  </code></pre>
  
  <p>All of those paths are valid, and exist.</p>