help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] ${var//!([[:class:]])} removing characters of the [:clas


From: Mart Frauenlob
Subject: Re: [Help-bash] ${var//!([[:class:]])} removing characters of the [:class:]
Date: Sun, 27 Jan 2013 09:07:49 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 27.01.2013 01:24, Clark WANG wrote:
On Sat, Jan 26, 2013 at 3:13 PM, Mart Frauenlob
<address@hidden <mailto:address@hidden>> wrote:

    Hello,

    am I wrong if I think that an extglob pattern of i.e. !([[:digit:]])
    should match all non-digit characters? Why don't they match in the
    example below? Why are non-digit chars removed?

    # cat extg
    #!/bin/bash

    shopt -s extglob

    echo "address@hidden"

    x=".:3:."

    echo "Y${x}"
    echo remove digits
    echo "Y${x//@([[:digit:]])}"
    echo remove non-digits
    echo "Y${x//!([[:digit:]])}"


According to the bash manual, !(pattern-list) would match "anything
except one of the given patterns". But the matching is string based
rather than char based. So ${x//!([[:digit:]])} removed the string
".:3:." which does not match the pattern [[:digit:]].

More example:

$ shopt -s extglob
$ v=foobar
$ echo ${v//!(foo)/xxx}
xxx
$ echo ${v//!(bar)/xxx}
xxx
$


um, ok, thank you.

But I don't know how to explain this result:

$ echo ${v//!(foobar)/xxx}
xxxxxx
$

indeed strange.

x=abc
$ echo "${x/!([[:alpha:]])}"

$ echo "${x/[![:alpha:]]}"
abc

still why does the first example remove all alphabetic chars, there can't be a match???

[...]




reply via email to

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