Error when using certain directory path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error when using certain directory path
# 1  
Old 03-12-2013
Error when using certain directory path

Hi, I am using the following code to check if directory is empty:
Code:
if [ -z `ls $indir/ITC*.zip` ]; then
    echo "There is no files in the input"
 sleep 60
fi

And indir path is:
Code:
/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!
# 2  
Old 03-12-2013
It's because of the ARG_MAX limit of your system.
With bash, I would write something like this:

Code:
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

This User Gave Thanks to radoulov For This Post:
# 3  
Old 03-12-2013
Thanks a lot!
# 4  
Old 03-12-2013
How about:-
Code:
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
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 03-12-2013
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:
Code:
shopt -s nullglob
while :; do
  set -- "$indir"/ITC*.zip
  (( ${#@} )) && break
  printf 'no files\n'
  sleep 60
done
shopt -u nullglob


Last edited by radoulov; 03-12-2013 at 10:49 AM..
This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies

2. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

3. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

4. Shell Programming and Scripting

Keep last directory from path

Hello, I am looking for a command that will give me the last directory name from a path ex 1 : /dir1/dir/2/dir3/ output needed dir3 ex 2 : /dir1/dir/2/dir3/dir4/ output needed dir4 (1 Reply)
Discussion started by: Aswex
1 Replies

5. Shell Programming and Scripting

How to get the directory name from a path using csh?

Hi, I want to get ABC and 924 from this path. How can i do so? The length of the path can vary from but end will we same. /home/abs/cad/bad_BAD/vdhingra/testcases/ABC/924/work Similarly, CBA and 234 from this path. /home/abs/cad/aaa/bad_BAD/vdhingra/testcases/CBA/234/work (5 Replies)
Discussion started by: vdhingra123
5 Replies

6. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

7. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

8. AIX

AIX cp error: "A file or directory in the path does not exist"

Hello fellow UNIX fans, I'm running AIX 4.3 and getting an error message “cp: /a/file2.db: A file or directory in the path does not exist” when I run the following command: cp /b/file.db /a/file2.db It stops every time about 95% of the way through the copy process at 1,073,741,312 bits. ... (3 Replies)
Discussion started by: Jackson123
3 Replies

9. UNIX for Dummies Questions & Answers

How to get directory name from its path?

If I the path to a directory, what command can I use to return the actual name of that directory. test=`pwd`/folder1 > $test folder1 I'd rather avoid anything with regular expressions. Any ideas? (1 Reply)
Discussion started by: ordano
1 Replies

10. Shell Programming and Scripting

Truncate directory path

Is it possibe to use sed for the following? I would like to truncate the output of a directory path if it's over 3 directory levels deep. For example: /dir1/dir2/dir3 -- NO change required but, /dir1/dir2/dir3/dir4 would output as ~/dir4 Thanks. (4 Replies)
Discussion started by: here2learn
4 Replies
Login or Register to Ask a Question