🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: mod.std.unix
Article #387

Re: file times and shell commands

#387
From: Moderator, John Quarterman
Date: Tue, 04 Nov 1986 17:28
71 lines
2783 bytes
From: arnold@emory.arpa  (Arnold D. Robbins)
Date: Mon, 3 Nov 86 13:20:48 EST
Organization: Math & Computer Science, Emory University, Atlanta

In article <6177@ut-sally.UUCP>:
>From: mayer@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@emory	BITNET:	arnold@emoryu1
ARPA:	arnold%emory.csnet@csnet-relay.arpa
UUCP:	{ akgua, decvax, gatech, sb1, sb6, sunatl }!emory!arnold

Volume-Number: Volume 8, Number 33
Technical Details
Message-ID: <6225@ut-sally.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!sri-spam!mordor!lll-crg!seismo!ut-sally!std-unix
References: <6177@ut-sally.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!sri-spam!mordor!lll-crg!seismo!ut-sally!std-unix
From: std-unix@ut-sally.UUCP (Moderator, John Quarterman)
Newsgroups: mod.std.unix
Subject: Re: file times and shell commands
Message-ID: <6225@ut-sally.UUCP>
Date: Tue, 4-Nov-86 12:28:22 EST
Article-I.D.: ut-sally.6225
Posted: Tue Nov  4 12:28:22 1986
Date-Received: Wed, 5-Nov-86 06:23:33 EST
References: <6177@ut-sally.UUCP>
Organization: IEEE P1003 Portable Operating System for Computer Environments Committee
Lines: 71
Approved: jsq@sally.utexas.edu