From: Teemu Likonen on
* 2010-03-02 12:09 (-0800), Ed Morton wrote:

> I agree. Its a mystery why just replacing one string with another
> should be harder to code than replacing an RE with a string.

If Bash counts, there is of course this:

$ foo=something
$ echo ${foo/something/else}
else
From: Ed Morton on
On 3/2/2010 10:40 PM, Teemu Likonen wrote:
> * 2010-03-02 12:09 (-0800), Ed Morton wrote:
>
>> I agree. Its a mystery why just replacing one string with another
>> should be harder to code than replacing an RE with a string.
>
> If Bash counts, there is of course this:
>
> $ foo=something
> $ echo ${foo/something/else}
> else

Doesn't help, it's not a simple string replacement:

$ foo=something
$ bar=something
$ echo ${foo/$bar/else}
else
$ bar=somestring
$ echo ${foo/$bar/else}
something
$ bar=so*ng
$ echo ${foo/$bar/else}
else

Regards,

Ed.
From: Teemu Likonen on
* 2010-03-02 23:17 (-0600), Ed Morton wrote:

> Doesn't help, it's not a simple string replacement:
>
> $ foo=something
> $ bar=something
> $ echo ${foo/$bar/else}
> else
> $ bar=somestring
> $ echo ${foo/$bar/else}
> something
> $ bar=so*ng
> $ echo ${foo/$bar/else}
> else

It think it does help. It's a simpler replacement than regexps.
From: pk on
Ed Morton wrote:

> On 3/2/2010 10:40 PM, Teemu Likonen wrote:
>> * 2010-03-02 12:09 (-0800), Ed Morton wrote:
>>
>>> I agree. Its a mystery why just replacing one string with another
>>> should be harder to code than replacing an RE with a string.
>>
>> If Bash counts, there is of course this:
>>
>> $ foo=something
>> $ echo ${foo/something/else}
>> else
>
> Doesn't help, it's not a simple string replacement:
>
> $ foo=something
> $ bar=something
> $ echo ${foo/$bar/else}
> else
> $ bar=somestring
> $ echo ${foo/$bar/else}
> something
> $ bar=so*ng
> $ echo ${foo/$bar/else}
> else

Quoting matters:

$ echo "${foo/$bar/else}"
else

$ echo ${foo/"$bar"/else}
something

$ echo "${foo/"$bar"/else}"
something

So $bar is expanded if unquoted, and taken literally if quoted.
From: Ed Morton on
On 3/3/2010 3:11 AM, pk wrote:
> Ed Morton wrote:
>
>> On 3/2/2010 10:40 PM, Teemu Likonen wrote:
>>> * 2010-03-02 12:09 (-0800), Ed Morton wrote:
>>>
>>>> I agree. Its a mystery why just replacing one string with another
>>>> should be harder to code than replacing an RE with a string.
>>>
>>> If Bash counts, there is of course this:
>>>
>>> $ foo=something
>>> $ echo ${foo/something/else}
>>> else
>>
>> Doesn't help, it's not a simple string replacement:
>>
>> $ foo=something
>> $ bar=something
>> $ echo ${foo/$bar/else}
>> else
>> $ bar=somestring
>> $ echo ${foo/$bar/else}
>> something
>> $ bar=so*ng
>> $ echo ${foo/$bar/else}
>> else
>
> Quoting matters:
>
> $ echo "${foo/$bar/else}"
> else
>
> $ echo ${foo/"$bar"/else}
> something
>
> $ echo "${foo/"$bar"/else}"
> something
>
> So $bar is expanded if unquoted, and taken literally if quoted.

That'll teach me to copy-paste without thinking. Can't believe I just left a
variable unquoted - aaarghhhh! Having said that, I would've thought this:

echo "${foo/$bar/else}"

was adequate quoting and that this:

echo "${foo/"$bar"/else}"

was quoting everything except $bar so I wouldn't have tried quoting it the right
way anyway.

Thanks,

Ed.