home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10546 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  2.9 KB

  1. Path: sparky!uunet!auspex-gw!guy
  2. From: guy@Auspex.COM (Guy Harris)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: A question on ls
  5. Message-ID: <14375@auspex-gw.auspex.com>
  6. Date: 30 Aug 92 23:28:41 GMT
  7. References: <6786@tekig7.PEN.TEK.COM> <1992Aug30.154653.27976@mccc.edu>
  8. Sender: news@auspex-gw.auspex.com
  9. Distribution: na
  10. Organization: Auspex Systems, Santa Clara
  11. Lines: 60
  12. Nntp-Posting-Host: bootme.auspex.com
  13.  
  14. >=What command would I type to display all files that do not have a .Z 
  15. >=extension ?
  16. >
  17. >ls *[!.][!Z]
  18.  
  19. What shell will display *all* files that do not have a ".Z" extension
  20. with such a command?
  21.  
  22. Not the SunOS 4.1.1 Bourne shell (essentially the SVR3.1 Bourne shell),
  23. and not the "ksh-88" version of the Korn shell:
  24.  
  25.     bootme$ ls
  26.     foo.Z           foo.c           fooZ            foofoofoo       x
  27.     bootme$ ls *[!.][!Z]        # ksh-88
  28.     foofoofoo
  29.     bootme$ /bin/sh            # 4.1.1 Bourne shell
  30.     bootme$ ls *[!.][!Z]
  31.     foofoofoo
  32.  
  33. They may list "foofoofoo", but they don't list "foo.c" (which doesn't
  34. have a ".Z" extension), nor "fooZ" (which doesn't have a ".Z"
  35. extension), nor "x" (which doesn't have a ".Z" extension).
  36.  
  37. To quote the 4.1.1 SH(1) manual page (essentially an SVR3-vintage manual
  38. page):
  39.  
  40.   Filename Generation
  41.      Before a command is executed, each command word  is  scanned
  42.      for the characters `*', `?', and `['.  If one of these char-
  43.      acters appears the word is regarded as a pattern.  The  word
  44.      is  replaced with alphabetically sorted filenames that match
  45.      the pattern.  If no filename is found that matches the  pat-
  46.      tern,  the word is left unchanged.  The character `.' at the
  47.      start of a filename or immediately following a `/', as  well
  48.      as the character `/' itself, must be matched explicitly.
  49.  
  50.           *    Matches any string, including the null string.
  51.           ?    Matches any single character.
  52.           [...]
  53.                Matches any one of  the  enclosed  characters.   A
  54.                pair  of  characters  separated by `-' matches any
  55.                character lexically between the  pair,  inclusive.
  56.                If  the first character following the opening [ is
  57.                a ! any character not enclosed is matched.
  58.  
  59. Sounds to me as if:
  60.  
  61.     1) "[!.]" matches any character that's not a ".", but will not
  62.        match nothing, just as "[!Z]" matches any character that's
  63.        not "Z", but doesn't match nothing.  Thus, "[!.][!Z]" doesn't
  64.        match any name that has fewer than 2 characters, e.g. ".x".
  65.  
  66.     2) "*[!.][!Z]" matches anything that doesn't have "." as its
  67.        next-to-last character and that doesn't have "Z" as its last
  68.        character - emphasis on the "and".  I.e., it doesn't match
  69.        anything with "." as its next-to-last character, even if it
  70.        doesn't have "Z" as its last character (e.g., "foo.c"), and
  71.        doesn't match anything with "Z" as its last character, even
  72.        if it doesn't have "." as its next-to-last character (e.g.,
  73.        "fooZ").
  74.