home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / mod.std.unix.v8 / text0032.txt < prev    next >
Encoding:
Internet Message Format  |  1987-06-30  |  2.1 KB

  1. From: arnold@emory.arpa  (Arnold D. Robbins)
  2. Date: Mon, 3 Nov 86 13:20:48 EST
  3. Organization: Math & Computer Science, Emory University, Atlanta
  4.  
  5. In article <6177@ut-sally.UUCP>:
  6. >From: mayer@rochester.arpa  (Jim Mayer)
  7. >Date: Wed, 29 Oct 86 22:15:54 est
  8. >
  9. >[....]
  10. >
  11. >There doesn't appear to be any decent way to compare the last modified
  12. >times of files from the shell.  I have written programs to do this,
  13. >but that makes any scripts I write using the programs essentially
  14. >unexportable.
  15. >
  16. >There are several approaches to fixing the problem:
  17. >
  18. >1. Extend the "test" command, perhaps by borrowing the "-newer" syntax
  19. >   of "find".
  20. >[....]
  21.  
  22. The Korn shell did just this. In addition to the standard options listed
  23. in the (System V) test(1) man page, there are four more options:
  24.  
  25.     -L    [ -L file ]; true if file is a symbolic link
  26.     -nt    [ file1 -nt file2 ]; true if file1 is newer than file 2
  27.     -ot    [ file1 -ot file2 ]; true if file1 is older than file 2
  28.     -ef    [ file1 -ef file2 ]; true if file1 and file 2 same device/inode
  29.  
  30. The -L option will always be false on System V. The -ef goes through symbolic
  31. links; you have to use [ f1 -ef f2 -a ! -L f1 -a ! -L f2 ] to be absolutely
  32. sure.
  33.  
  34. >[....]
  35. >All three work, however the second points out a problem with the
  36. >Bourne shell: there is no "not" operator!
  37.  
  38. As has been pointed out in other forums, the S5 /bin/sh and the ksh both
  39. support shell functions:
  40.  
  41.     not () {        # also "function not {" in ksh
  42.         if "$@"
  43.         then return 1
  44.         else return 0
  45.         fi
  46.     }
  47.  
  48.     if not x y z a ...
  49.     then
  50.         whatever
  51.     fi
  52.  
  53. Older /bin/sh versions leave you no choice:
  54.  
  55.     if x y z a ...
  56.     then    :
  57.     else
  58.         whatever
  59.     fi
  60.  
  61. A standard "not" operator would be nice, but shell functions and the test
  62. stuff outlined above would be even better! (No, let's not start a debate
  63. about shell functions vs. aliases vs. other shell features. We've already
  64. been through that once on unix-wizards a while back.)
  65. -- 
  66. Arnold Robbins
  67. CSNET:    arnold@emory    BITNET:    arnold@emoryu1
  68. ARPA:    arnold%emory.csnet@csnet-relay.arpa
  69. UUCP:    { akgua, decvax, gatech, sb1, sb6, sunatl }!emory!arnold
  70.  
  71. Volume-Number: Volume 8, Number 33
  72.  
  73.