[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] pattern replacement experiment
From: |
Ken Irving |
Subject: |
Re: [Help-bash] pattern replacement experiment |
Date: |
Wed, 21 Mar 2012 11:36:39 -0800 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On Wed, Mar 21, 2012 at 12:55:05PM -0600, Bill Gradwohl wrote:
> answer='012345'
> modifier='?/.'
> echo $answer ${answer//?/.} ${answer//${modifier}}
>
> address@hidden ycc# ./tst
> 012345 ...... 012345
>
> I expected either for it to work or give me 'bad substitution'.
>
> I didn't expect what I got.
>
> Is it because ${modifier} is considered the pattern only , and not the
> pattern plus the string?
It seems odd to try to put part of the substitution operator in a
variable. I guess you're expecting $modifier to be expanded in place
like a preprocessor macro? Eval would probably do what you want I
suppose, but it works with variables holding the parameters separately:
$ answer=012345
$ pat=?
$ sub=y
$ echo $answer ${answer//?/.} ${answer//$pat/$sub}
012345 ...... yyyyyy
Ken