bug-bash
[Top][All Lists]
Advanced

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

Re: Infinite loop in bash glob matching


From: Eduardo Bustamante
Subject: Re: Infinite loop in bash glob matching
Date: Tue, 16 May 2017 09:49:49 -0500

On Tue, May 16, 2017 at 2:48 AM, Zoltán Herczeg <address@hidden> 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?

address@hidden:~/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
address@hidden:~/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
address@hidden:~/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:

address@hidden:~/t$ ls
a:  aa  ab
address@hidden:~/t$ ls a[[:alpha:][:abm]
a:
address@hidden:~/t$ ../glob
a:
aa
ab
address@hidden:~/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;
}



reply via email to

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