bug-bash
[Top][All Lists]
Advanced

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

pattern deletion with extended patterns deletes first character


From: Donald C. Coleman
Subject: pattern deletion with extended patterns deletes first character
Date: Tue, 10 Dec 2002 02:09:14 -0800

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: freebsd4.7
Compiler: cc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='freebsd4.7' -DCONF_MACHTYPE='i386-portbld-freebsd4.7' 
-DCONF_VENDOR='portbld' -DSHELL  -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib 
 -O -pipe
uname output: FreeBSD kestrel 4.7-RELEASE FreeBSD 4.7-RELEASE #0: Wed Oct  9 
15:08:34 GMT 2002     root@builder.freebsdmall.com:/usr/obj/usr/src/sys/GENERIC
  i386
Machine Type: i386-portbld-freebsd4.7

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
        with shopt -s extglob set, parameter expansion in the form of
        "${parameter/pattern/string}" where the pattern is an extended
        pattern using ?() and *() deletes non-pattern matching components.

        eg:
                # delete leading zeros, if any.
                shopt -s extglob
                foo=123
                echo ${foo/#*(0)}
                23                      # bad!
                echo ${foo/#?(0)}
                23                      # bad!
                echo ${foo/#+(0)}
                123                     # good!
                echo ${foo##*(0)}
                123                     # good!
                echo ${foo##*(0)}
                123                     # good!

        All these should echo the same result -- "123", but the
        first one instead returns "23", deleting the leading 1. 
        The "+" does the correct thing (returning 123), as does
        "${foo##*(0)}".

        This worked correctly in bash version 2.02.1(1)-release 
        (on BSD/OS 4.2), though "${foo/#+(0)}" didn't work correctly 
        in this version.


Repeat-By:
        shopt -s extglob
        foo=123
        echo ${foo/#*(0)}






reply via email to

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