[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Syntax error when using extended patterns inside functions
From: |
CANTIN Francois |
Subject: |
Syntax error when using extended patterns inside functions |
Date: |
Sun, 23 Jun 2002 19:13:25 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4.1) Gecko/20020314 Netscape6/6.2.2 |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -D_GNU_SOURCE -I. -I. -I./include -I./lib -O2 -march=i386 -mcpu=i686
uname output: Linux r96m70.cybercable.tm.fr 2.4.18-4 #1 Thu May 2 18:47:38 EDT
2002 i686 unknown
Machine Type: i686-pc-linux-gnu
Bash Version: 2.05a
Patch Level: 0
Release Status: release
Description:
While executing a function, a syntax error occurs when some
extended pattern matching features appear in a '[[' compound
command.
The same '[[' compound command outside a function works well.
Similar behaviour with the 'case' compound command and the
pathname expansion.
No error with the parameter expansion.
Repeat-By:
Here is a small procedure to reproduce the problem:
========================================================================
#/bin/bash
function z {
shopt -s extglob;
shopt -p extglob;
# No error.
i=aaafoo; echo ${i%%f+(o)};
# ==========> Syntax error at the following lines.
[[ foo == f+(o) ]] && echo MATCH_INSIDE || echo NO_MATCH_INSIDE;
case 'foo' in (f+(o)) echo yes;; esac
touch z; ls @(z);
help u@(mask|nset); # May be fixed by quoting the pattern.
return $?;
}
# Test outside a function.
shopt -s extglob;
shopt -p extglob;
i=aaafoo; echo ${i%%f+(o)};
[[ foo == f+(o) ]] && echo MATCH_OUTSIDE || echo NO_MATCH_OUTSIDE;
case 'foo' in (f+(o)) echo yes;; esac
touch z; ls @(z);
help u@(mask|nset);
# Test inside a function.
z;
exit $?;
========================================================================
Execute it once, then comments out the function content and execute again.
Execution example:
1 $ ./test_extglob.sh
2 ./test_extglob.sh: line 11: syntax error in conditional expression
3 ./test_extglob.sh: line 11: syntax error near unexpected token `f+(o'
4 ./test_extglob.sh: line 11: ` [[ foo == f+(o) ]] && echo MATCH_INSIDE
|| echo NO_MATCH_INSIDE;'
5 $ bash -v ./test_extglob.sh
6 #/bin/bash
7
8 function z {
9 shopt -s extglob;
10 shopt -p extglob;
11
12 # No error.
13 i=aaafoo; echo ${i%%f+(o)};
14
15 # ==========> Syntax error at the following lines.
16 [[ foo == f+(o) ]] && echo MATCH_INSIDE || echo NO_MATCH_INSIDE;
17 ./test_extglob.sh: line 11: syntax error in conditional expression
18 ./test_extglob.sh: line 11: syntax error near unexpected token `f+(o'
19 ./test_extglob.sh: line 11: ` [[ foo == f+(o) ]] && echo MATCH_INSIDE
|| echo NO_MATCH_INSIDE;'
20 # Puts 'z' function inside in comment and try again.
21 $ ./test_extglob.sh
22 shopt -s extglob
23 aaa
24 MATCH_OUTSIDE
25 yes
26 z
27 Shell commands matching keyword `u@(mask|nset)'
28
29 umask: umask [-p] [-S] [mode]
30 The user file-creation mask is set to MODE. If MODE is omitted, or
if
31 `-S' is supplied, the current value of the mask is printed. The
`-S'
32 option makes the output symbolic; otherwise an octal number is
output.
33 If `-p' is supplied, and MODE is omitted, the output is in a form
34 that may be used as input. If MODE begins with a digit, it is
35 interpreted as an octal number, otherwise it is a symbolic mode
string
36 like that accepted by chmod(1).
37 unset: unset [-f] [-v] [name ...]
38 For each NAME, remove the corresponding variable or function. Given
39 the `-v', unset will only act on variables. Given the `-f' flag,
40 unset will only act on functions. With neither flag, unset first
41 tries to unset a variable, and if that fails, then tries to unset a
42 function. Some variables cannot be unset; also see readonly.
43 shopt -s extglob
44 aaa
Fix:
[Description of how to fix the problem. If you don't know a
fix for the problem, don't include this section.]
- Syntax error when using extended patterns inside functions,
CANTIN Francois <=