help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] pattern replacement experiment


From: Greg Wooledge
Subject: Re: [Help-bash] pattern replacement experiment
Date: Wed, 21 Mar 2012 15:21:09 -0400
User-agent: Mutt/1.4.2.3i

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

> Is it because ${modifier} is considered the pattern only , and not the
> pattern plus the string?

Yes.  Storing the search pattern and the replacement string in variables
is the standard way to work around things that otherwise don't work
at all.

imadev:~$ input="don't worry" search="'" replace='`'
imadev:~$ echo "${input//$search/$replace}"
don`t worry

imadev:~$ input=/usr/local/bin/bash search=/ replace='\'
imadev:~$ echo "${input//$search/$replace}"
\usr\local\bin\bash

In your (rightmost) example, you were searching for the string ?/. which
of course was not present in the input.



reply via email to

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