On Tuesday 18 April 2006 07:11, Benno Schulenberg <[EMAIL PROTECTED]> wrote about 'Re: [gentoo-user] shell script': > Zac Slade wrote: > > On Tuesday 18 April 2006 00:34, [EMAIL PROTECTED] wrote: > > > In a shellp script, let > > > STRING="a.txt b.txt c.txt" > > > And I want to delete a sub-string from $STRING, for example > > > b.txt, and then we got > > > $STRING is "a.txt c.txt" > > > > So for what you want just do: > > STRING="a.txt b.txt c.txt" > > ${STRING:-b.txt} > > That doesn't work. This does:
Yeah, I don't know why someone would ever think that STRING="a.txt b.txt c.txt" made STRING empty or undefined. Or why substituting in the value "b.txt" would give the desired "a.txt c.txt". (Hi Zac! :P) > $ STRING="a.txt b.txt c.txt" > $ REMOVE="b.txt" > $ echo ${STRING/$REMOVE/} > a.txt c.txt However, it actually leave an extra space in the variable, which got swallowed by your shell since you didn't quote the expansion. Following the above with: $ echo "${STRING/$REMOVE/}" a.txt c.txt You might try either including the leading or trailing space in REMOVE or running the string through shell expansion (as you did by calling echo without quoting the expansion) The original poster might want to look into bash arrays, esp. since the ${VARIABLE/MATCH/REPLACEMENT} expansion doesn't work in sh either (so we are already into bash-specific shell), AFAIK. -- "If there's one thing we've established over the years, it's that the vast majority of our users don't have the slightest clue what's best for them in terms of package stability." -- Gentoo Developer Ciaran McCreesh
pgpMlq52k7weG.pgp
Description: PGP signature