Re: Long command lines

Hello,

AIM: Need to test for the presence of some files (*.F) in a certain directory.

having a problem with this line is ksh:

if test `ls $SOMEDIR/dir/*.F \
2>/dev/null|wc -w` -eq 0

Basically testing for the presence of *.F files in the specified directory. If the return code from 'wc -w' is equal to 0 then no *.F exist

BUT, ls can fail if the command line is too long.
Fails with ..
sh-42 sh: arg list too long.

Could use the find command:

find $SOMEDIR/dir/*.F

along with the word count stuff, but then find is recursive and searches lower subdirectories (which I dont want). I cant find a command / option to use with 'find' to force it to only search that dir.
Any idea

Thanks in advance
E.

The option "-level 0" should limit it to the one directory

But few versions of find have that -level 0 option.

I would do:
cd somedir
ls | grep \\.F\$ | wc -l
to get a count of the *.F files. Then just compare that number to zero.

Sorry didn't know that. I'm only used to SCO.

You can use find if you use the -prune and/or -only options for find. I see prune is in the UNIX Nutshell book, but the -only option may not be available in some OSs.

They can help you limit your search parameters and prevent recursive directory searches.

if `find . -name "*.F" -prune -only 2>/dev/null |wc -l` -eq 0

This will only search the current direcory and give your comparison.

:slight_smile: