Xref: utzoo comp.unix.questions:24285 alt.sources.d:724 Path: utzoo!attcan!lsuc!sq!lee From: lee@sq.sq.com (Liam R. E. Quin) Newsgroups: comp.unix.questions,alt.sources.d Subject: Re: how to compare file modification time (whole dir tree?) Message-ID: <1990Aug3.155651.12006@sq.sq.com> Date: 3 Aug 90 15:56:51 GMT References: <1990Jul27.153223.12416@chinet.chi.il.us> <1446@chinacat.Unicom.COM> <1990Aug2.195056.4041@laguna.ccsf.caltech.edu> Followup-To: comp.unix.questions,alt.sources.d Organization: SoftQuad Inc. Lines: 46 fritz@mercury.caltech.edu (Fritz Nordby) writes: > Am I missing something here, or will the following [work]? > >#!/bin/sh >case $# in 2);;*)echo "usage: ${0:-newer} file1 file2" >&2;exit 2;;esac >[ ! -f "$2" -o -f "$1" -a "X`/bin/ls -t \"\$1\" \"\$2\"`" = "X$1 >$2"] >/dev/null 2>&1 I have no idea. It *might* have won the Obfuscated Shell Contest, except that there isn't one. At first I thought it was a perl script. I have had a go at expanding this a little below... although I'd probably use find(1) instead for this. [I mised the original article, presumably there was some reason not to use find apart from ``I don't understand it''] Lee #! /bin/sh # valilidate arguments: case $# in 2) ;; *) echo "usage: ${0:-newer} file1 file2" >&2 exit 2 ;; esac if [ ! -f "$2" -o ! -f "$1" ] then # we might want to print an error message here?? exit 1 fi LsOuput=`/bin/ls -dt "$1" "$2"` FirstNewer="$1 $2" test x"${LsOutput}" = x"${FirstNewer} exit $? -- Liam R. E. Quin, lee@sq.com, {utai,utzoo}!sq!lee, SoftQuad Inc., Toronto ``He left her a copy of his calculations [...] Since she was a cystologist, she might have analysed the equations, but at the moment she was occupied with knitting a bootee.'' [John Boyd, Pollinators of Eden, 217]