Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!ogicse!decwrl!uunet!wgate!lanzo From: lanzo@wgate.UUCP (Mark Lanzo) Newsgroups: comp.unix.questions Subject: Re: how to compare file modification time in bourne shell script Message-ID: <105@atesysv.UUCP> Date: 26 Jul 90 13:03:13 GMT References: <1990Jul23.233044.2729@silma.com> <840@ehviea.ine.philips.nl> Reply-To: lanzo@atesysv.UUCP (Mark Lanzo) Organization: Wandel & Goltermann Technologies, RTP, NC Lines: 35 Someone asks: > > I need to compare the modification times of two files in a bourne shell > script. I would like to do this without writing C code. > Machine is Sparcstation 1 running SunOS 4.03c > Thus I need a function: > > newer file1 file2 > > that returns 0 if file1 is newer than file2 else returns 1 > Try this: #!/bin/sh newer() { f1="$1" set -- `ls -ct -- "$f1" "$2"` test "$1" = "$f1" return $? # This line isn't really necessary } as written, this function presupposes that $1 and $2 refer to accessible files (else the ls command will pop up with a "not found" type of error). -- Mark Lanzo Wandel & Goltermann Technologies, Inc. Home (919)481-2406 1030 Swabia Court Play (919)941-5730 Research Triangle Park uunet.uu.net!wgate.com!lanzo North Carolina 27709-3585