bug-bash
[Top][All Lists]
Advanced

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

set command output can have syntax error (extglob problem)


From: Stanislav Brabec
Subject: set command output can have syntax error (extglob problem)
Date: Wed, 24 Nov 2004 16:09:19 +0100

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux
Compiler: gcc -I/usr/src/packages/BUILD/bash-3.0 
-L/usr/src/packages/BUILD/bash-3.0/../readline-5.0
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux' -DCONF_MACHTYPE='x86_64-suse-linux' -DCONF_VENDOR='suse' 
-DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H  -I.  
-I. -I./include -I./lib   -O2 -fmessage-length=0 -Wall -D_GNU_SOURCE -Wall 
-pipe -g -fbranch-probabilities
uname output: Linux hammer 2.6.8-24-default #1 Wed Oct 6 09:16:23 UTC 2004 
x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-suse-linux

Bash Version: 3.0
Patch Level: 0
Release Status: release

Description:

set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
              Without  options,  the  name  and value of each shell variable 
are displayed in a format that can be reused as
              input.  The output is sorted according to the current locale.

Documentation says nothing about the fact, that in non POSIX mode
functions are also listed.

If function is defined with extglob, reuse of set output can cause
syntax error.

Repeat-By:

#! /bin/bash
shopt -s extglob
function isnum () 
{
    case "$1" in 
        +([0-9]))
            echo $1 is number
            ;;
        *)
            echo $1 is not number
            ;;
    esac
}
shopt -u extglob
unset POSIXLY_CORRECT
set >bashbug_temp
. bashbug_temp

Script output:
> sh bashbug
bashbug_temp: line 3: BASH_VERSINFO: readonly variable
bashbug_temp: line 14: EUID: readonly variable
bashbug_temp: line 74: PPID: readonly variable
bashbug_temp: line 82: SHELLOPTS: readonly variable
bashbug_temp: line 90: UID: readonly variable
bashbug_temp: line 137: syntax error near unexpected token `('
bashbug_temp: line 137: `        +([0-9]))'

Fix:

Set proper shopt before extglob definition or accept extglob patterns in
function definitions in non-extglob mode, too.

Document, that set output in non POSIX mode contains list of functions,
too.

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SuSE CR, s. r. o.                             e-mail: sbrabec@suse.cz
Drahobejlova 27                               tel: +420 296 542 382
190 00 Praha 9                                fax: +420 296 542 374
Czech Republic                                http://www.suse.cz/





reply via email to

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