# Error when using certain directory path

**URL:** <https://community.unix.com/t/error-when-using-certain-directory-path/325578>\
**Category:** Shell Programming and Scripting\
**Created:** [March 12, 2013, 7:48am UTC](https://community.unix.com/t/error-when-using-certain-directory-path/325578 "2013-03-12T07:48:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apenkov](https://community.unix.com/letter_avatar/apenkov/32/5_5575768a8748004e209b776fc1b2916d.png) [@apenkov](https://community.unix.com/u/apenkov)\
**Post date:** [March 12, 2013, 7:48am UTC](https://community.unix.com/t/error-when-using-certain-directory-path/325578/1 "2013-03-12T07:48:21Z")

</div>

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

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

```

And indir path is:

```nohighlight
/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!

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [March 12, 2013, 8:09am UTC](https://community.unix.com/t/error-when-using-certain-directory-path/325578/2 "2013-03-12T08:09:37Z")

</div>

It's because of the [ARG\_MAX](http://www.in-ulm.de/~mascheck/various/argmax/) limit of your system.  
With bash, I would write something like this:

```plaintext
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

```

---

<div class="post-metadata">

**Author:** ![apenkov](https://community.unix.com/letter_avatar/apenkov/32/5_5575768a8748004e209b776fc1b2916d.png) [@apenkov](https://community.unix.com/u/apenkov)\
**Post date:** [March 12, 2013, 8:12am UTC](https://community.unix.com/t/error-when-using-certain-directory-path/325578/3 "2013-03-12T08:12:57Z")

</div>

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/5_5575768a8748004e209b776fc1b2916d.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [March 12, 2013, 9:02am UTC](https://community.unix.com/t/error-when-using-certain-directory-path/325578/4 "2013-03-12T09:02:06Z")

</div>

How about:-

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![radoulov](https://community.unix.com/user_avatar/community.unix.com/radoulov/32/489_2.png) [@radoulov](https://community.unix.com/u/radoulov)\
**Post date:** [March 12, 2013, 9:29am UTC](https://community.unix.com/t/error-when-using-certain-directory-path/325578/5 "2013-03-12T09:29:19Z")

</div>

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:

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

```
