Searching for file and stopping at first item found

Hello,

I try to write a shell script that would list all files on a directory and stop when it finds the first item specified on a find or ls command.
How can I tell to the find or ls command to stop when it finds the first ".doc" file for example ?

Thank you

Try...

for i in *
do
   if [[ `basename $i .doc` != "$i" ]]; then
      exit
   fi
   echo $i
done

Pipe it into head, eg

find /path -type f -name '*.doc' -print | head -1
find . -type f -name *.doc 2>/dev/null | sed "q"

thank you rakeshawasthi it works
but how can I make the script goes through subdirectories ?
I've tried this, but all the files comes into the "i" variable, so the script doesnt work :
IFS=
for i in $(find . -type f | awk -F"/" ' { print $2 } ' )
do
if [[ `basename "$i" .chm` != "$i" ]]; then
exit
fi
echo $i
done

Why you are using

Isnt this enough...

find . -type f -print
i.e.
for i in `find . -type f -print`
ls -lRa /path |awk '/\.doc$/{print;exit}'

it seems all the comand lines you give me are not working :frowning:
I found this on a linux machine : -quit parameter for find.
This is the result I'd like to get :

ls -l
drwxrwxr-x 2 usr grp 96 2009-07-02 16:06 .
drwxr-xr-x 27 usr grp 8192 2009-07-02 16:06 ..
-rw-rw-r-- 1 usr grp 0 2009-07-02 16:06 1.txt
-rw-rw-r-- 1 usr grp 0 2009-07-02 16:06 2.doc
-rw-rw-r-- 1 usr grp 0 2009-07-02 16:06 3.txt
-rw-rw-r-- 1 usr grp 0 2009-07-02 16:06 4.doc

server:/home/usr/test>find . -name '*.doc' -print -quit

./2.doc
server:/home/usr/test>