cancel
Showing results for 
Search instead for 
Did you mean: 

scripting question -

 
Highlighted
Frequent Advisor

scripting question -

Hi ,

 

I am trying to check if files are present  inside the directory or not,  but getting error,  not sure if the syntax is correct,

 

 

if [ -f /home/myfiles/* ]
then
echo "files found "
else
echo "files not found"

##########################

 

 

can you guys advise, whats wrong  

Thanks,

 

 

 

3 REPLIES 3
Highlighted
Acclaimed Contributor

Re: scripting question (empty directory)

-f only works on one file at a time.  You need to use something like:

if [ ! -z $( ls /home/myfiles 2> /dev/null ) ]; then

   echo "files found"

Highlighted
Frequent Advisor

Re: scripting question -

Dennis,

Thanks,

what is the -z is stands for. is it checking for zero byte,

 

 

 

 

 

Highlighted
Acclaimed Contributor

Re: scripting question (empty directory)

>what is the -z is stands for. Is it checking for zero byte,

 

You can look at the man ages for test(1), ksh(1) or sh-posix(1).

This is if the string has zero length and "! -z" means not empty.