Comparing modified times of files

J|rgen Jensen jensen at diku.dk
Mon Apr 1 05:15:41 AEST 1991


krs at uts.amdahl.com (Kris Stephens [Hail Eris!]) writes:

  >In article <6067 at iron6.UUCP> yeates at motcid.UUCP (Tony J Yeates) writes:
  >>krs at uts.amdahl.com (Kris Stephens [Hail Eris!]) writes:
  >>
  >>># sh or ksh fragment
  >>>newest() {
  >>>	set -- ls -t $* 2>/dev/null
  >>>	echo $1
  >>>	}
  >>>oldest() {
  >>>	set -- ls -rt $* 2>/dev/null
  >>>	echo $1
  >>>	}
  >>
  >>Can you have functions in Bourne Shell scripts?  I thought this was 
  >>only available in Ksh.
  >
  >Well, it works in my Bourne shell.  :-)
  >...Kris
  >-- 

well, *functions* work in my Bourne shell too, but the above 
doesn't -- shouldn't a pair of back-ticks (`) enter into the
thing somewhere?-)

my favorite way of comparing the recentness of *two* files follows
(I believe that was the original poster's problem):

   :
   #!/bin/sh -
   # 
   if find $1 -newer $2 -print -o -prune | read a
   then echo $1 is newer than $2
   fi

   # if your find doesn't have a "-prune"-predicate this
   # won't work for directories.  some older finds (SysV?)
   # didn't support filenames where "$1" is inserted
   # -- i think -- then this won't work at all, of course.


-- 

 . . . . . . . . . . . . . . . . . . . . . . . . . . j e n s e n
(jensen at diku.dk)
                        Opinions? -- These are rock-solid facts!



More information about the Comp.unix.shell mailing list