help-bash
[Top][All Lists]
Advanced

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

extglob and ()/{}


From: Peng Yu
Subject: extglob and ()/{}
Date: Mon, 5 Apr 2021 19:55:45 -0500

Hi,

The following code works fine.

$ cat main1.sh
#!/usr/bin/env bash
shopt -s extglob
while (($#)); do
    case $1 in
        *([_A-Z0-9]) )
            echo $1
            ;;
    esac
    shift
done
$ ./main1.sh A a
A

But if I use () and {} to enclose the same code, it will not work.
Does anybody know what is wrong with it? How to use () and {} to
enclose the code when extglob syntax is used?

$ cat main2.sh
#!/usr/bin/env bash
(
shopt -s extglob
while (($#)); do
    case $1 in
        *([_A-Z0-9]) )
            echo $1
            ;;
    esac
    shift
done
)
$ ./main2.sh  A a
./main2.sh: line 8: syntax error near unexpected token `('
./main2.sh: line 8: `        *([_A-Z0-9]) )'
$ cat main3.sh
#!/usr/bin/env bash
{
shopt -s extglob
while (($#)); do
    case $1 in
        *([_A-Z0-9]) )
            echo $1
            ;;
    esac
    shift
done
}
$ ./main3.sh
./main3.sh: line 8: syntax error near unexpected token `('
./main3.sh: line 8: `        *([_A-Z0-9]) )'

-- 
Regards,
Peng



reply via email to

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