[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Infinite loop in bash glob matching
From: |
Daniel Mills |
Subject: |
Re: Infinite loop in bash glob matching |
Date: |
Tue, 16 May 2017 11:08:17 -0400 |
The '[:' may be messing with it, 'a[[:alpha:]:abm[]' should work. It won't
match 'amm' because the range only matches a single character, you'd need
'a+([[:alpha:]:abm[])'
On Tue, May 16, 2017 at 10:49 AM, Eduardo Bustamante <dualbus@gmail.com>
wrote:
> On Tue, May 16, 2017 at 2:48 AM, Zoltán Herczeg <hzmester@freemail.hu>
> wrote:
> > Hi,
> >
> > bash enter an infinite loop for this glob:
> >
> > ls @(@()).
>
> It works fine for me. What version of Bash are you using? And, what
> files are in the directory you're testing in?
>
> dualbus@debian:~/t$ ls
> a.1 a.2 a.3 a.4 b.1 b.2 b.3 b.4 c.1 c.2 c.3 c.4 d.1 d.2 d.3
> d.4
> dualbus@debian:~/t$ ls @(@()).
> a.1 a.2 a.3 a.4 b.1 b.2 b.3 b.4 c.1 c.2 c.3 c.4 d.1 d.2 d.3
> d.4
> dualbus@debian:~/t$
> GNU bash, version 4.4.11(1)-release (x86_64-pc-linux-gnu)
>
>
> > I have been trying to create a bash glob regex converter. It would be
> great if somebody (privately) could explain me how !() and invalid []
> expressions exactly work. I have questions such as:
> >
> > ls a[[:alpha:][:abm]
> >
> > Why does this match to a: and nothing else (e.g. am or a[mm )?
>
> The shell globbing library seems to be interpreting this pattern
> weirdly. I don't know the answer for this, but the glob() call in
> glibc does what I expect:
>
> dualbus@debian:~/t$ ls
> a: aa ab
> dualbus@debian:~/t$ ls a[[:alpha:][:abm]
> a:
> dualbus@debian:~/t$ ../glob
> a:
> aa
> ab
> dualbus@debian:~/t$ cat ../glob.c
> #include <stdlib.h>
> #include <stdio.h>
> #include <glob.h>
>
> int main() {
> int i;
> glob_t pglob;
> if(glob("a[[:alpha:][:abm]", 0, NULL, &pglob))
> perror(NULL);
> for(i = 0; i < pglob.gl_pathc; i++) {
> puts(pglob.gl_pathv[i]);
> }
> return 0;
> }
>
>
- Infinite loop in bash glob matching, Zoltán Herczeg, 2017/05/16
- Re: Infinite loop in bash glob matching, Eduardo Bustamante, 2017/05/16
- Re: Infinite loop in bash glob matching,
Daniel Mills <=
- Re: Infinite loop in bash glob matching, Zoltán Herczeg, 2017/05/16
- Re: Infinite loop in bash glob matching, Eduardo Bustamante, 2017/05/17
- Re: Infinite loop in bash glob matching, Chet Ramey, 2017/05/17
- Re: Infinite loop in bash glob matching, Zoltán Herczeg, 2017/05/18
- Re: Infinite loop in bash glob matching, Greg Wooledge, 2017/05/18
- Re: Infinite loop in bash glob matching, Chet Ramey, 2017/05/18