Re: Bash substrings – just can’t figure it out…

Johnny Rosenberg gurus.knugum at gmail.com
Tue Jan 31 18:52:43 UTC 2012


2012/1/31 Cybe R. Wizard <cybe_r_wizard at earthlink.net>:
> On Tue, 31 Jan 2012 12:31:06 -0600
> "Cybe R. Wizard" <cybe_r_wizard at earthlink.net> wrote:
>
>> On Tue, 31 Jan 2012 19:07:20 +0100
>> Johnny Rosenberg <gurus.knugum at gmail.com> wrote:
>>
>> > I have an example here:
>> > File="03. Rock Nuts.flac"
>> > echo "${File##N*s}"
>> >
>> > The result should be ”03. Rock .flac”, shouldn't it? Obviously not,
>> > because the result is ”03. Rock Nuts.flac”, which is exactly the
>> > original string.
>> > So what am I missing?
>>
>> Knowing little about BASH, I'm nevertheless immediately drawn to the
>> fact that your example is missing the space you wish in our output.
>>
>> Cybe
>
> Just noticed that you're trying to pull out, "Nuts."
> Sorry for the noise.

No, there were no noise. I was trying to delete Nuts in my example,
but the following question was about pulling out ”Rock Nuts” in the
same example. Sorry for being confusing.

According to http://tldp.org/LDP/abs/html/string-manipulation.html ##,
#, %% and % is for substring removal and // is for substring
replacement. Isn't that correct?
If it is, shouldn't echo "${File##N*s}" pull out ”Nuts” from my
example? Why not?

”stringZ=abcABC123ABCabc
#       |----|          shortest
#       |----------|    longest

echo ${stringZ#a*C}      # 123ABCabc
# Strip out shortest match between 'a' and 'C'.

echo ${stringZ##a*C}     # abc
# Strip out longest match between 'a' and 'C'.”


So shouldn't, in my example, echo ${File##N*s} ”strip out” longest
match between 'N' and 's'?
What's the difference between my example and theirs, except that mine
doesn't work?


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ
>
> Cybe R. Wizard
> --




More information about the ubuntu-users mailing list