Shell scripting and test expressions
- by Paul
Hi, I'm trying to test whether a directory path exists when a file is passed to my script. I use dirname to strip and save the path. I want my script to run only if the path exists. This is my attempt below.
FILE=$1
   DIRNAME=dirname $FILE
if [ -z $DIRNAME ] ; then
       echo "Error no file path"
       exit 1
   fi
But this doesn't work. Actual when there is no file path dirname $FILE still returns "." to DIRNAME, i.e. this directory. So how do i distinguish between "." and "/bla/bla/bla".
Thanks.