Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!cbnews!cbnewsl!bonnie!rbr From: rbr@bonnie.ATT.COM (228-4197,ATTT) Newsgroups: comp.unix.shell Subject: Re: ksh: Checking for file existence Message-ID: <1991Jun17.120641.19548@cbnewsl.att.com> Date: 17 Jun 91 12:06:41 GMT References: <91165.101842RS0VRD@ROHVM1.BITNET> Sender: news@cbnewsl.att.com (NetNews Administrator) Reply-To: rbr@bonnie.ATT.COM (Bob Rager) Distribution: usa Organization: AT&T Bell Laboratories Lines: 63 In article <91165.101842RS0VRD@ROHVM1.BITNET> RS0VRD@ROHVM1.BITNET (Ross Druker) writes: >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@rohmhaas.com Try something like: if test -r `ls *.data` or: filelist=`ls *.data` for FN in `echo $filelist` do if test -r "$FN" ; then fi done Bob Rager Ain't no place like ${HOME}.