file times and shell commands
Moderator, John Quarterman
std-unix at ut-sally.UUCP
Wed Nov 5 03:28:22 AEST 1986
From: arnold at emory.arpa (Arnold D. Robbins)
Date: Mon, 3 Nov 86 13:20:48 EST
Organization: Math & Computer Science, Emory University, Atlanta
In article <6177 at ut-sally.UUCP>:
>From: mayer at rochester.arpa (Jim Mayer)
>Date: Wed, 29 Oct 86 22:15:54 est
>
>[....]
>
>There doesn't appear to be any decent way to compare the last modified
>times of files from the shell. I have written programs to do this,
>but that makes any scripts I write using the programs essentially
>unexportable.
>
>There are several approaches to fixing the problem:
>
>1. Extend the "test" command, perhaps by borrowing the "-newer" syntax
> of "find".
>[....]
The Korn shell did just this. In addition to the standard options listed
in the (System V) test(1) man page, there are four more options:
-L [ -L file ]; true if file is a symbolic link
-nt [ file1 -nt file2 ]; true if file1 is newer than file 2
-ot [ file1 -ot file2 ]; true if file1 is older than file 2
-ef [ file1 -ef file2 ]; true if file1 and file 2 same device/inode
The -L option will always be false on System V. The -ef goes through symbolic
links; you have to use [ f1 -ef f2 -a ! -L f1 -a ! -L f2 ] to be absolutely
sure.
>[....]
>All three work, however the second points out a problem with the
>Bourne shell: there is no "not" operator!
As has been pointed out in other forums, the S5 /bin/sh and the ksh both
support shell functions:
not () { # also "function not {" in ksh
if "$@"
then return 1
else return 0
fi
}
if not x y z a ...
then
whatever
fi
Older /bin/sh versions leave you no choice:
if x y z a ...
then :
else
whatever
fi
A standard "not" operator would be nice, but shell functions and the test
stuff outlined above would be even better! (No, let's not start a debate
about shell functions vs. aliases vs. other shell features. We've already
been through that once on unix-wizards a while back.)
--
Arnold Robbins
CSNET: arnold at emory BITNET: arnold at emoryu1
ARPA: arnold%emory.csnet at csnet-relay.arpa
UUCP: { akgua, decvax, gatech, sb1, sb6, sunatl }!emory!arnold
Volume-Number: Volume 8, Number 33
More information about the Mod.std.unix
mailing list