help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Why `echo !(*.l).c` behaves different depending on the c


From: Peng Yu
Subject: Re: [Help-bash] Why `echo !(*.l).c` behaves different depending on the context?
Date: Sat, 9 Feb 2019 00:03:56 -0600

On Fri, Feb 8, 2019 at 11:20 PM Eduardo Bustamante <address@hidden> wrote:
>
> On Fri, Feb 8, 2019 at 9:05 PM Peng Yu <address@hidden> wrote:
> (...)
> > I am not sure this link is relevant.
>
> OK, since you didn't read the link:
>
> | extglob changes the way certain characters are parsed. It is
> necessary to have a newline (not just a semicolon) between shopt -s
> extglob and any subsequent commands to use it. **You cannot enable
> extended globs
> | inside a group command that uses them**, because **the entire
> block** is parsed before the shopt is evaluated. Note that the typical
> function body is a group command. An unpleasant workaround could be to
> use a subshell
> | command list as the function body.

I still get the error when I use subshell. Do I miss something here?

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

function f {
    (
        shopt -s extglob
        echo !(*.l).c
    )
}

set -v
f
$ ./main.sh
./main.sh: line 7: syntax error near unexpected token `('
./main.sh: line 7: `        echo !(*.l).c'

-- 
Regards,
Peng



reply via email to

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