title: Using bash to create a directory in HDFS if the directory does not exist
body: <p>I want to test whether a directory exists in the Hadoop Distributed File System (HDFS). I want to create the directory if it does not exist and do nothing otherwise.</p>
  
  <p>When I modify the code at <a href="http://jugnu-life.blogspot.com/2012/10/hadoop-fs-test-example.html" rel="nofollow">http://jugnu-life.blogspot.com/2012/10/hadoop-fs-test-example.html</a>:</p>
  
  <pre><code>#!/bin/bash
  directory=/raw/tool/
  
  if hadoop fs -test –d $directory ; then
      echo "Directory  exists"
  else
      hadoop fs -mkdir $directory
      echo "Creating  directory"
  fi
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>-test: Too many arguments: expected 1 but got 2
  Usage: hadoop fs [generic options] -test -[defsz] &lt;path&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>