From: Teemu Likonen on 2 Mar 2010 23:40 * 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 3 Mar 2010 00:17 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 3 Mar 2010 03:26 * 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 3 Mar 2010 04:11 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 3 Mar 2010 07:50 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.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: search pattern and display lines around the pattern Next: Processing stdin in blocks |