ksh: Checking for file existence

Rob McMahon cudcv at warwick.ac.uk
Wed Jun 19 19:12:25 AEST 1991


In article <1991Jun15.031252.6351 at chinet.chi.il.us> les at chinet.chi.il.us
(Leslie Mikesell) writes: 
>This should work with sh or ksh:
>FILES=`echo *.data`
>if [ "*.data" = "$FILES" ]
>  then :  # no match
>else
>  for i in $FILES
>   do
>  ... process them...
>   done
>fi

... unless you've got a file called `*.data', or a file with a space in the
name ... how about 

set - *.data
if [ "$*" = "*.data" -a ! -f "*.data" ]
then
  : no files
else
  for i
  do
    ... process them ...
  done
fi

Yuck,

Rob
-- 
UUCP:   ...!mcsun!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv at uk.ac.warwick             INET:   cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England



More information about the Comp.unix.shell mailing list