bug-bash
[Top][All Lists]
Advanced

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

Re: Problem with pattern replacing when STRING is an expandable char


From: Heinz-Ado Arnolds
Subject: Re: Problem with pattern replacing when STRING is an expandable char
Date: Thu, 13 Dec 2007 09:18:30 +0100
User-agent: Thunderbird 1.5.0.13 (X11/20070809)

Mike Stroyan wrote:
Repeat-By:
    a=111.1
    echo ${a//[0-9]/x}

    correctly gives "xxx.x", but

    echo ${a//[0-9]/*}

    gives a listing of files in current directory. Seems that the "*"
    is expanded before replacing the pattern.

    It workes the right way at least up to bash-3.1.17(1)-release

    But if you set

    a=111

    it doesn't even work in 3.1.17 right.

  The pathname expansion of "*" is not done until after the parameter
expansion substitution.  That is the documented behavior.  The following
example shows that echo of the "***.*" pattern matches files and
directories that have a "." in their name.  Setting a to "111" results
in a pathname pattern of "***" that matches all of the files.
Double quoting the substitution prevents pathname expansion.

$ echo $BASH_VERSION
3.2.25(1)-release
$ touch a b c.d e.f
$ ls
a  b  c.d  e.f
$ a=111.1
$ echo ${a//[0-9]/*}
c.d e.f
$ echo "${a//[0-9]/*}"
***.*
$ a=111
$ echo ${a//[0-9]/*}
a b c.d e.f
$ echo "${a//[0-9]/*}"
***
$

Thanks a lot for your fast response! Ok, even after so many years
bash is astounding if you don't have all expansion rules in mind
every time.

Kind regards,

Ado





reply via email to

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