ksh: Checking for file existence

Ross Druker RS0VRD at ROHVM1.BITNET
Sat Jun 15 01:18:42 AEST 1991


I have what may be a trivial problem, but I haven't solved it yet.
I'm using the Korn shell a script on an HP-UX system.  I would like
to check for the existence of ANY data files, not a specific file.
I was trying to use the "test" command.  This HP-UX does NOT have the
[[...]] operator, even though this was supposedly available after
1986 versions of ksh, :-(

I would like to do:

if test -r  *.data

But ksh barks back with a syntax error.  test doesn't like wildcards.
I've been trying to get around this, playing with quotes, etc.  The
last thing I tried was to assign the list of filenames to a variable,
as in:

filelist=*.data

What I've discovered is that ksh does NOT assign the corresponding
string to filelist.  In the csh world you'd get a wordlist.  For
instance, in csh, if there were files a.data and b.data,

echo $filelist AND echo "$filelist" both return:
a.data b.data

But in ksh, echo $filelist returns:
a.data b.data

and echo "$filelist" returns:
*.data

The filelist variable never takes on the value of the filenames really.
I was heading this way to possibly try and extract the first filename
from the variable and see if I could use that somehow.  But then I
ran into this.

Sorry to be so verbose, but does anyone have the answer that I'm too
blind to see?


Ross Druker
Rohm and Haas Co.
rs0vrd at rohmhaas.com



More information about the Comp.unix.shell mailing list