From: pk on
Ben Finney wrote:

>> re: foo(bar)?
>> glob: ... you can't do that.
>
> For example, in Bash, the above could be written as the pathname glob
> ?foo{,bar}?. There's no such capability in Posix AFAIK, though.

There's a difference between the expansion you mention and what's usually
considered "globbing".

foo{,bar}

will unconditionally expand to "foo foobar" regardless of whether either
file actually exists in the current directory, so if you do

rm foo{,bar}

you'll get "file not found" if one of the two file (or both) is not present.
On the other hand, "globbing" usually means some expression that expands to
a list that's dependent on which files exist that match the pattern.
So for example with bash extended globbing, using

foo?(bar)

will expand to a list containing only the names that match actual files (or
remain unchanged if no file matches - or expand to nothing is nullglob is
set).

That said, there are places where glob expressions are used more like
regular expressions (ie aren't matched against file names), like in "case"
statements or bash {var//} expansion.
From: Stephane CHAZELAS on
2010-01-24, 06:11(+01), Janis Papanagnou:
> Seebs wrote:
>>
>> I'm not sure that even ksh can do everything posix REs can.
>
> I am confident and quite sure it does. Vice versa; I think the regexp
> library will at least have problems emulating ksh's !(...) construct.
> Ever tried? In general you'll get extremely bulky results here!
> But the class of languages (regular expressions) is the same, anyway.[*]
>
> [*] N.B. Newer ksh's also support back-references in their expressions,
> so strictly speeking, with that feature, they exceed the Chomsky-3 grammar
> class as well (analogous to other libraries with backreference extensions).
[...]

Recent versions of AT&T ksh can also convert globbing patterns
to regular expressions (a AT&T variant thereof):

$ ksh -c 'printf "%R\n" "!(...)"'
^(\.\.\.)!$

I agree ksh or zsh or bash patterns now offer the same
possibilities (more or less) as the regular expressions, but
it's not the case of the standard shell patterns and it's a
different syntax and approach because they have been originally
designed to match file names, so they shouldn't be confused.

Note that all 3 shells now also support regular expression
matching (beside shell pattern matching) (again with different
syntaxes, and again which vary from version to version, so
nothing standard or usable portably here).

--
St�phane
From: Stephane CHAZELAS on
2010-01-24, 04:02(+01), Janis Papanagnou:
> Sven Mascheck wrote:
>> [...]
>>
>> Regular expression implementations show even more variations in
>> practice than globbing, but they are sufficiently different from
>> globbing on unix, so that it doesn't make sense to mix terms.
>
> The terminology is already foobar'ed. People now seem to associate the
> concepts of regular expressions (as defined by formal language theory)
> bound to the regexp library on Unix (BRE and ERE). And they call every
> extension of those functions still as regular expressions, whether they
> are or not. Usability extensions (like the \d and many others) are okay,
> but even backreferences are introduced in some tools and the libs and
> expressions are still called regular, even it they are not.

POSIX BREs have back references, it's the one thing they have
over EREs (
http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03_06).


[...]
>> PS: why are they characteristically different:
>> The motivation for globbing was *intuitive* handling of file names
>
> Certainly, because before System 7 (AFAIK) there was no built-in globbing
> in bourne shell, rather there was an external program for that expansion.

There was no Bourne shell before V7 (at least in any /released/
version of Unix).

[...]
> Frankly, I've never used an old UNIX edition 6 bourne shell and don't know
> how the case statement worked at that time, or whether the case statement
> was existing at all. Sven, wasn't that you who had access to old bourne
> shells? You may want to inspect whether the case statement was there, and
> if so, what patterns and regular expression metacharacters it had suported.
[...]

Again, there was no Bourne shell in V6, the Bourne shell was
first released in V7. V6's sh was the Thomson shell.

Ealier Unices had a "glob" command:
http://minnie.tuhs.org/UnixTree/V4/usr/man/man7/glob.7.html

I don't there was a "case" construct or command before V7. From
a look at the manuals online (tuhs.org is a good source).

--
St�phane
From: Sven Mascheck on
Janis Papanagnou wrote:

> It's probably worth to adapt to that fuzzy terminology from a
> practical point of view, but if you're viewing that from a formal language
> theory point of view it's not that clear any more what's the preferable way.

I believe we agree very much here.

> you can convert unanchored regexp's to anchored "globbing-pattern" and vice
> versa.

And my intention for pointing out, e.g., implicit anchoring in the unix terms
(glob vs regexp) is not to confuse it from the point of formal language, but
just to think about the original motivations which lead to the unix subsets
and terms.

> Frankly, I've never used an old UNIX edition 6 bourne shell and don't know
> how the case statement worked at that time, or whether the case statement
> was existing at all.

The Thompson shell had no control structures [1], but the PWB shell [2]
had switch, which also made use of the /etc/glob command. (the different
shell was motivated by providing for large amounts of procedural automation)

[1] http://www.in-ulm.de/~mascheck/bourne/#predecessors
[2] http://www.in-ulm.de/~mascheck/bourne/PWB/
From: Janis Papanagnou on
Stephane CHAZELAS wrote:
> 2010-01-24, 06:11(+01), Janis Papanagnou:
>> Seebs wrote:
>>> I'm not sure that even ksh can do everything posix REs can.
>> I am confident and quite sure it does. Vice versa; I think the regexp
>> library will at least have problems emulating ksh's !(...) construct.
>> Ever tried? In general you'll get extremely bulky results here!
>> But the class of languages (regular expressions) is the same, anyway.[*]
>>
>> [*] N.B. Newer ksh's also support back-references in their expressions,
>> so strictly speeking, with that feature, they exceed the Chomsky-3 grammar
>> class as well (analogous to other libraries with backreference extensions).
> [...]
>
> Recent versions of AT&T ksh can also convert globbing patterns
> to regular expressions (a AT&T variant thereof):
>
> $ ksh -c 'printf "%R\n" "!(...)"'
> ^(\.\.\.)!$

I didn't knew that ! were a regular expression meta operator in regexp.

The ! _regexp_ meta operator does not seem to produce results on my box.

$ ls
hello hello world helloworld regexp world
$ ls !(hello)
hello world helloworld regexp world
$ ksh -c 'printf "%R\n" "!(hello)"'
^(hello)!$
$ ls | egrep '^(hello)!$'
### nothing matched ###

It works well with the known operators + and * etc. resp. +(...) *(...) etc.

Still interested in an regexp expression conforming to !(...) ext. glob.

Janis

>
> [...]