help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Filename Expansion: Find Utility vs Bash Shell Pattern M


From: Greg Wooledge
Subject: Re: [Help-bash] Filename Expansion: Find Utility vs Bash Shell Pattern Matching
Date: Wed, 17 Jun 2015 14:10:45 -0400
User-agent: Mutt/1.4.2.3i

On Wed, Jun 17, 2015 at 09:18:10AM -0700, Michael Convey wrote:
> However, I'm trying to understand why
> the operators work differently under different circumstances.

Because they are implemented differently.

> For example,
> according to the following link, 'find -name' appears to use fnmatch(),

Irrelevant.

> whereas bash appears to use glob():
> http://www.linuxselfhelp.com/gnu/glibc/html_chapter/libc_10.html

No, it uses its own internal modified variant of an older version of
fnmatch(), as Chet Ramey said earlier.

> That is probably an oversimplification, but I'm still trying to wrap my
> brain around this. Once I understand the underlying mechanism/function for
> each use case, I'll be able to learn the defaults and options of those
> underlying mechanisms, which will enhance my understanding of the big
> picture. Thanks again!!

A long time ago in a galaxy far away, a bunch of different Unix commands
that used regular expressions all had different regular expression parsers
built into them.  The REs used by grep were different from the REs used
by sed, which were different from the REs used by ed, and so on.

Then one day, some people decided this was confusing nonsense, and
standardized the world of regular expressions into two kinds: Basic (BRE)
and Extended (ERE).  Now, grep and sed use BREs, and grep -E uses EREs.
Bash's =~ operator also uses EREs.  So, when you're looking at someone
else's program that uses a BRE or an ERE, you have a small chance of
being able to understand what it does.

(Then perl happened, and broke everything all over again, but that's a
different chapter.)

That same unification has NOT taken place for glob patterns.  Every
implementation of globbing is slightly different.  There are no standards.
You seem to be asking "which library function does ___ use" as if that
would reveal the answer to the your real question "to which globbing
standard does ____ conform", but there are no such standards in the
first place.

Right now, you just have to learn each program's features one by one.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]