Error when using certain directory path

Hi, I am using the following code to check if directory is empty:

if [ -z `ls $indir/ITC*.zip` ]; then
    echo "There is no files in the input"
 sleep 60
fi

And indir path is:

/CH_ROOT/PRD/MAIN/INPUT/SDNTL/Interconnect

Only when I am using the above path I get an error "too many arguments". I tried with 10 different directories and it works without any problem. Does anyone know what can be the problem?

Thanks!

It's because of the ARG_MAX limit of your system.
With bash, I would write something like this:

unset files
shopt -s nullglob
until (( ${#files[@]} )); do
  files=( "$indir"/ITC*.zip )
  printf 'no files in %s\n' "$indir"
  sleep 60
done
shopt -u nullglob
# unset files if you do not need the filenames

Thanks a lot!

How about:-

ls $indir | egrep -c "\/ITC.*\.zip$"

This lists all files in the directory and then counts those that match the pattern. I have specified the pattern as starting with a / which I have to escape, hence the preceding \, then the ITC bit, I then have .* to signify any number of characters then .zip$ to finish the line. The . before the zip has also to be escaped as it's a wildcard for a single character.

I hope that this helps,

Robin
Liverpool/Blackburn
UK

EDIT: The above solution involves external commands and in this case it could be avoided.

You could get rid of the files array by using the code below:

shopt -s nullglob
while :; do
  set -- "$indir"/ITC*.zip
  (( ${#@} )) && break
  printf 'no files\n'
  sleep 60
done
shopt -u nullglob