What effect does "shopt -s extglob" has on "find" command in bash ?

What effect does "shopt -s extglob" has on "find" command in bash ?

am 01.02.2008 09:16:25 von Eric

I have turned on extglob in bash, but it behaves very strange when I
use find command. Please see:

shsvr:/home/tom/tmp/test1$ echo $SHELL
/bin/bash
shsvr:/home/tom/tmp/test1$ shopt -s extglob
shsvr:/home/tom/tmp/test1$ ls *
-rw-r--r-- 1 tom msc 0 Feb 1 15:47 File1.java
-rw-r--r-- 1 tom msc 0 Feb 1 15:47 File2.java
-rw-r--r-- 1 tom msc 0 Feb 1 15:47 Makefile

SCCS:
total 0
-rw-r--r-- 1 tom msc 0 Feb 1 15:47 s.File1.java
-rw-r--r-- 1 tom msc 0 Feb 1 15:47 s.Makefile
-rw-r--r-- 1 tom msc 0 Feb 1 15:47 s.File2.java

shsvr:/home/tom/tmp/test1$ find . -name !(s.*.java)
find: paths must precede expression
Usage: find [path...] [expression]

shsvr:/home/tom/tmp/test1$ find SCCS -name !(s.*.java)
find: paths must precede expression
Usage: find [path...] [expression]

shsvr:/home/tom/tmp/test1$ cd SCCS
shsvr:/home/tom/tmp/test1/SCCS$ find . -name !(s.*.java)
../s.Makefile

What should I do to make find works properly ?

Thanks in advance.

Re: What effect does "shopt -s extglob" has on "find" command in bash ?

am 01.02.2008 12:14:24 von Bill Marcum

On 2008-02-01, Eric wrote:
>
>
> I have turned on extglob in bash, but it behaves very strange when I
> use find command. Please see:
>

>
> shsvr:/home/tom/tmp/test1$ find . -name !(s.*.java)
> find: paths must precede expression
> Usage: find [path...] [expression]
>
The argument following -name is usually quoted so the shell won't expand
it. Find is an external command, so its globbing isn't affected by bash
shopt options, but you can use:

find . ! -name 's.*.java'

Re: What effect does "shopt -s extglob" has on "find" command in bash ?

am 01.02.2008 12:41:54 von Stephane CHAZELAS

On Fri, 1 Feb 2008 06:14:24 -0500, Bill Marcum wrote:
> On 2008-02-01, Eric wrote:
>>
>>
>> I have turned on extglob in bash, but it behaves very strange when I
>> use find command. Please see:
>>
>
>>
>> shsvr:/home/tom/tmp/test1$ find . -name !(s.*.java)
>> find: paths must precede expression
>> Usage: find [path...] [expression]
>>
> The argument following -name is usually quoted so the shell won't expand
> it. Find is an external command, so its globbing isn't affected by bash
> shopt options, but you can use:
>
> find . ! -name 's.*.java'

Note that strictly speaking, find is not doing globbing, that is
it doesn't expand the wildcard pattern into a list of files as
the shell does. Instead it uses the pattern on the basename of
every file it is walking through to decide whether it matches or
not (and going on or not with the other predicates). So it is
doing "matching" only.

In shells, wildcard patterns can be used both for globbing
(filename generation) as in

echo *.txt
which it expands into echo x.txt y.txt...
or for matching as in

case $text in
($pattern) ...
esac

or ${var#$pattern}...

--
Stephane

Re: What effect does "shopt -s extglob" has on "find" command in bash

am 01.02.2008 12:54:47 von Eric

On Feb 1, 7:41=A0pm, Stephane Chazelas
wrote:
> On Fri, 1 Feb 2008 06:14:24 -0500, Bill Marcum wrote:
> > On 2008-02-01, Eric wrote:
>
> >> I have turned on extglob in bash, but it behaves very strange when I
> >> use find command. Please see:
>
> >> shsvr:/home/tom/tmp/test1$ find . =A0-name !(s.*.java)
> >> find: paths must precede expression
> >> Usage: find [path...] [expression]
>
> > The argument following -name is usually quoted so the shell won't expand=

> > it. =A0Find is an external command, so its globbing isn't affected by ba=
sh
> > shopt options, but you can use:
>
> > find . ! -name 's.*.java'
>
> Note that strictly speaking, find is not doing globbing, that is
> it doesn't expand the wildcard pattern into a list of files as
> the shell does. Instead it uses the pattern on the basename of
> every file it is walking through to decide whether it matches or
> not (and going on or not with the other predicates). So it is
> doing "matching" only.
>
> In shells, wildcard patterns can be used both for globbing
> (filename generation) as in
>
> echo *.txt
> which it expands into echo x.txt y.txt...
> or for matching as in
>
> case $text in
> =A0 ($pattern) ...
> esac
>
> or ${var#$pattern}...
>
> --
> Stephane- Hide quoted text -
>
> - Show quoted text -


Thanks. I know now. I just want a more powerful find utility so that I
can find files using very complicated criteria(regular expressions).
Are there any kinds of tool available ? I am puzzled that why there
is no an enhanced find utility. Its filename matching is too weak.

Re: What effect does "shopt -s extglob" has on "find" command in bash ?

am 01.02.2008 12:59:03 von Stephane CHAZELAS

On Fri, 1 Feb 2008 03:54:47 -0800 (PST), Eric wrote:
[...]
> Thanks. I know now. I just want a more powerful find utility so that I
> can find files using very complicated criteria(regular expressions).
> Are there any kinds of tool available ? I am puzzled that why there
> is no an enhanced find utility. Its filename matching is too weak.

GNU and FreeBSD find have the -iregex and -regex predicate which
should be enough for any need.

But in any case, you can run any utility to do the matching with
the -exec predicate.

find . -exec awk 'BEGIN{exit(!(ARGV[1] ~ /pattern/))}' {} \; -print

for instance.

--
Stephane

Re: What effect does "shopt -s extglob" has on "find" command in bash ?

am 01.02.2008 13:03:05 von Stephane CHAZELAS

On 01 Feb 2008 11:59:03 GMT, Stephane Chazelas wrote:
> On Fri, 1 Feb 2008 03:54:47 -0800 (PST), Eric wrote:
> [...]
>> Thanks. I know now. I just want a more powerful find utility so that I
>> can find files using very complicated criteria(regular expressions).
>> Are there any kinds of tool available ? I am puzzled that why there
>> is no an enhanced find utility. Its filename matching is too weak.
>
> GNU and FreeBSD find have the -iregex and -regex predicate which
> should be enough for any need.
>
> But in any case, you can run any utility to do the matching with
> the -exec predicate.
>
> find . -exec awk 'BEGIN{exit(!(ARGV[1] ~ /pattern/))}' {} \; -print
[...]

or of course:

find . -exec bash -c '
shopt -s extglob
case $1 in
(pattern) exit 0;;
(*) exit 1;;
esac' inline {} \; -print

(of course that won't be as fast as using find's own matching
operators)

Note that the zsh shell has the ability to replace find with its
recursive globbing:

print -rl -- **/complex-pattern

for instance.

--
Stephane

Re: What effect does "shopt -s extglob" has on "find" command in bash

am 01.02.2008 13:32:57 von Eric

On Feb 1, 8:03=A0pm, Stephane Chazelas
wrote:
> On 01 Feb 2008 11:59:03 GMT, Stephane Chazelas wrote:> On Fri, 1 Feb 2008 =
03:54:47 -0800 (PST), Eric wrote:
> > [...]
> >> Thanks. I know now. I just want a more powerful find utility so that I
> >> can find files using very complicated criteria(regular expressions).
> >> Are there any kinds of tool available ? =A0I am puzzled that why there
> >> is no an enhanced find utility. Its filename matching is too weak.
>
> > GNU and FreeBSD find have the -iregex and -regex predicate which
> > should be enough for any need.
>
> > But in any case, you can run any utility to do the matching with
> > the -exec predicate.
>
> > find . -exec awk 'BEGIN{exit(!(ARGV[1] ~ /pattern/))}' {} \; -print
>
> [...]
>
> or of course:
>
> find . -exec bash -c '
> =A0 shopt -s extglob
> =A0 case $1 in
> =A0 =A0 (pattern) exit 0;;
> =A0 =A0 (*) exit 1;;
> =A0 esac' inline {} \; -print
>
> (of course that won't be as fast as using find's own matching
> operators)
>
> Note that the zsh shell has the ability to replace find with its
> recursive globbing:
>
> print -rl -- **/complex-pattern
>
> for instance.
>
> --
> Stephane

Great! Thank you very much.

Re: What effect does "shopt -s extglob" has on "find" command in bash ?

am 01.02.2008 22:57:00 von Dan Mercer

"Eric" wrote in message news:47e375f8-8f5f-4003-8ca6-c6c1c97797f7@s37g2000prg.google groups.com...
: I have turned on extglob in bash, but it behaves very strange when I
: use find command. Please see:
:
: shsvr:/home/tom/tmp/test1$ echo $SHELL
: /bin/bash
: shsvr:/home/tom/tmp/test1$ shopt -s extglob
: shsvr:/home/tom/tmp/test1$ ls *
: -rw-r--r-- 1 tom msc 0 Feb 1 15:47 File1.java
: -rw-r--r-- 1 tom msc 0 Feb 1 15:47 File2.java
: -rw-r--r-- 1 tom msc 0 Feb 1 15:47 Makefile
:
: SCCS:
: total 0
: -rw-r--r-- 1 tom msc 0 Feb 1 15:47 s.File1.java
: -rw-r--r-- 1 tom msc 0 Feb 1 15:47 s.Makefile
: -rw-r--r-- 1 tom msc 0 Feb 1 15:47 s.File2.java
:
: shsvr:/home/tom/tmp/test1$ find . -name !(s.*.java)

This expanded to find . -name File1.java File2.java Makefile SCCS

-name doesn't support extended globbing and the patterns should be quoted
to avoid unintended expansion by the shell. What you really want is:

find . ! -name 's.*.java'

Dan Mercer

: find: paths must precede expression
: Usage: find [path...] [expression]
:
: shsvr:/home/tom/tmp/test1$ find SCCS -name !(s.*.java)
: find: paths must precede expression
: Usage: find [path...] [expression]
:
: shsvr:/home/tom/tmp/test1$ cd SCCS
: shsvr:/home/tom/tmp/test1/SCCS$ find . -name !(s.*.java)
: ./s.Makefile
:
: What should I do to make find works properly ?
:
: Thanks in advance.