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: Clark WANG
Subject: Re: [Help-bash] ${var//!([[:class:]])} removing characters of the [:class:]
Date: Sat, 26 Jan 2013 17:24:26 -0700

On Sat, Jan 26, 2013 at 3:13 PM, Mart Frauenlob <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
$

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

$ echo ${v//!(foobar)/xxx}
xxxxxx
$
 
echo remove punct
echo "Y${x//+([[:punct:]])}"
echo remove non-punct
echo "Y${x//!([[:punct:]])}"

# /opt/bash42/bin/bash extg
4.2.42(1)-release
Y.:3:.
remove digits
Y.::.
remove non-digits
Y
remove punct
Y3
remove non-punct
Y


Best regards

Mart



reply via email to

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