Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get file's name?

Status
Not open for further replies.

volcano

Programmer
Aug 29, 2000
136
HK
Hello guys and gals, I have gone through most of the thread. It seems my question may be too simple to be asked here :p

My case is that I have some PDFs in my directory under Solaris OS. I want to write a (Bourne) shell script to get those PDF file names and store in variables. So how could I do this? I need these names to fax the PDFs. But I couldn't hard-code those names.

Thanks!
 
You can store them in a loop to be processed individually:

for EACHPDF in `find /directory/path -name "*.PDF"` ; do
echo $EACHPDF
done


-jim
 
If you want to limit to the current directory, this might work.
It's not as elegant, granted.

#!/bin/sh
# limiting to cur dir unlike 'find' command
for EACHPDF in `ls -1 *.PDF *.pdf 2>out.err`
do
echo $EACHPDF
done # with EACHPDF

It also would allow something like this:

#!/bin/sh
# limiting to cur dir unlike 'find' command, and grepping for 'march'
# assuming dir contains something like this: ls -1 *.pdf
# february-week-4.pdf
# march-week-1.pdf
# march-week-2.pdf
# etc.
for EACHPDF in `ls -1 *.PDF *.pdf 2>out.err | grep -i march`
do
echo $EACHPDF
done # with EACHPDF


Granted, this is probably overkill. -S Visit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top