nisha
nisha

Reputation: 711

Shell Script for checking existence of a directory

if[-d /abmusr06/abm/users/dywrk01/run_time];
   then
     echo "Pack installation Failed"
     exit(1)
fi

This the above code fine?

Upvotes: 2

Views: 327

Answers (2)

Bert F
Bert F

Reputation: 87573

Assuming this is Bourne Shell (/bin/sh):

if [ -d /abmusr06/abm/users/dywrk01/run_time ]
then
    echo "Pack installation Failed"
    exit 1
fi
  • Put spaces around the brackets: if [ -d. Think of [ as a (key)word - it needs to stand by itself. You wouldn't say ls-l, you say ls(space)-l.
  • Use exit 1, not exit(1).
  • The semicolons are unnecessary if everything is on separate lines.
  • The above seems to work in Cygwin for me.

Upvotes: 3

ghostdog74
ghostdog74

Reputation: 342739

if [ -d "directory" ];then
 ....
fi

Upvotes: 0

Related Questions