Shell scripting and test expressions
Posted
by Paul
on Stack Overflow
See other posts from Stack Overflow
or by Paul
Published on 2010-05-24T12:13:34Z
Indexed on
2010/05/24
12:31 UTC
Read the original article
Hit count: 159
shell-scripting
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.
© Stack Overflow or respective owner