home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!auspex-gw!guy
- From: guy@Auspex.COM (Guy Harris)
- Newsgroups: comp.unix.questions
- Subject: Re: A question on ls
- Message-ID: <14375@auspex-gw.auspex.com>
- Date: 30 Aug 92 23:28:41 GMT
- References: <6786@tekig7.PEN.TEK.COM> <1992Aug30.154653.27976@mccc.edu>
- Sender: news@auspex-gw.auspex.com
- Distribution: na
- Organization: Auspex Systems, Santa Clara
- Lines: 60
- Nntp-Posting-Host: bootme.auspex.com
-
- >=What command would I type to display all files that do not have a .Z
- >=extension ?
- >
- >ls *[!.][!Z]
-
- What shell will display *all* files that do not have a ".Z" extension
- with such a command?
-
- Not the SunOS 4.1.1 Bourne shell (essentially the SVR3.1 Bourne shell),
- and not the "ksh-88" version of the Korn shell:
-
- bootme$ ls
- foo.Z foo.c fooZ foofoofoo x
- bootme$ ls *[!.][!Z] # ksh-88
- foofoofoo
- bootme$ /bin/sh # 4.1.1 Bourne shell
- bootme$ ls *[!.][!Z]
- foofoofoo
-
- They may list "foofoofoo", but they don't list "foo.c" (which doesn't
- have a ".Z" extension), nor "fooZ" (which doesn't have a ".Z"
- extension), nor "x" (which doesn't have a ".Z" extension).
-
- To quote the 4.1.1 SH(1) manual page (essentially an SVR3-vintage manual
- page):
-
- Filename Generation
- Before a command is executed, each command word is scanned
- for the characters `*', `?', and `['. If one of these char-
- acters appears the word is regarded as a pattern. The word
- is replaced with alphabetically sorted filenames that match
- the pattern. If no filename is found that matches the pat-
- tern, the word is left unchanged. The character `.' at the
- start of a filename or immediately following a `/', as well
- as the character `/' itself, must be matched explicitly.
-
- * Matches any string, including the null string.
- ? Matches any single character.
- [...]
- Matches any one of the enclosed characters. A
- pair of characters separated by `-' matches any
- character lexically between the pair, inclusive.
- If the first character following the opening [ is
- a ! any character not enclosed is matched.
-
- Sounds to me as if:
-
- 1) "[!.]" matches any character that's not a ".", but will not
- match nothing, just as "[!Z]" matches any character that's
- not "Z", but doesn't match nothing. Thus, "[!.][!Z]" doesn't
- match any name that has fewer than 2 characters, e.g. ".x".
-
- 2) "*[!.][!Z]" matches anything that doesn't have "." as its
- next-to-last character and that doesn't have "Z" as its last
- character - emphasis on the "and". I.e., it doesn't match
- anything with "." as its next-to-last character, even if it
- doesn't have "Z" as its last character (e.g., "foo.c"), and
- doesn't match anything with "Z" as its last character, even
- if it doesn't have "." as its next-to-last character (e.g.,
- "fooZ").
-