bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash conditional expressions


From: Michael J. Baars
Subject: Re: bash conditional expressions
Date: Thu, 18 Nov 2021 07:26:51 +0100
User-agent: Evolution 3.36.5 (3.36.5-2.fc32)

On Fri, 2021-11-12 at 19:48 +0100, Andreas Schwab wrote:
>       FILE1 -nt FILE2  True if file1 is newer than file2 (according to
>                        modification date).
> 
> Andreas.
> 

So now we have a relation for 'older than' and for 'newer than', but how about 
'oldest' (executable), and 'newest' (executable)?

I could only come up with this:

unset y; for x in $(find bin -mindepth 1 -name "*"); do if [[ ${x} -nt ${y} ]]; 
then y=${x}; fi; done; echo newest: ${y};
y="bin"; for x in $(find bin -mindepth 1 -name "*"); do if [[ ${x} -ot ${y} ]]; 
then y=${x}; fi; done; echo oldest: ${y};

As you can see, the way the commands are initialized is not identical, because:

'-nt' returns a true when 'if file1 exists and file2 does not'  (y in     
initialized by the first condition evaluated)
'-ot' returns a true when 'if file2 exists and file1 does not'  (y is not 
initialized by the first condition evaluated)

When you try to selectively link new executables, I think it is important that 
you do not only have relations for 'older than' and 'newer than', but also 
consistent (identically initializated)
relations for 'oldest' and 'newest'.

Mischa.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]