how to compare file modification time in bourne shell script

Chet Ramey chet at cwns1.CWRU.EDU
Sat Jul 28 00:48:06 AEST 1990


>newer file1 file2
>
>that returns 0 if file1 is newer than file2 else returns 1

If you didn't like the C program, then try this:

newer()
{
	if [ ! -f $1 ] ; then
		return 1
	fi

	if [ ! -f $2 ] ; then
		return 0
	fi

	if [ $1 -nt $2 ] ; then
		return 0
	else
		return 1
	fi
}

The `-nt' option to test exists in bash and ksh, at least.

Chet

-- 
Chet Ramey					``See Figure 1.''
Network Services Group
Case Western Reserve University	
chet at ins.CWRU.Edu		



More information about the Comp.unix.questions mailing list