0

The command ls -al dog RCS/dog,v returns

-rw-r--r-- 1 simon simon   0 Apr 13 19:25 dog
-r--r--r-- 1 simon simon 191 Apr 13 19:28 RCS/dog,v

indicating that RCS/dog,v is newer than dog, yet

if [[ RCS/$dog* -nt dog ]] ; then echo not older than dog ; else echo older than dog ; fi

returns older than dog. Since for a file not ending in ,v this comparison performs correctly it seems to be a problem with files ending in ,v. Could somebody suggest how to fix this please?

Leo Simon
  • 453
  • 3
    Besides not being clear if the $dog var is set to anything, globs are not expanded in [[ ... ]]: [[ /e* = /etc ]] || echo no => no. –  Apr 14 '20 at 02:47
  • Per ancient folk wisdom(?), 'you can't update an old dog with new revisions' :-) – dave_thompson_085 Apr 14 '20 at 04:52

1 Answers1

2

In your example, you're referring to a variable where your expression expects a literal:

if [[ RCS/$dog* -nt dog ]] ; then echo not older than dog ; else echo older than dog ; fi

That is,

  • This is a variable: $dog, and if unset, you'll get a something like RCS/* (or something else instead if $dog happens to be set to cat).

  • This is a literal: dog, and RCS/dog* would match RCS/dog,v

Thomas Dickey
  • 76,765