FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 01-31-2012, 05:31 PM
"Cybe R. Wizard"
 
Default Bash substrings – just can’t figure it out…

On Tue, 31 Jan 2012 19:07:20 +0100
Johnny Rosenberg <gurus.knugum@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 R. Wizard
--
Strength through Unity.
Unity through faith.
Adam Sutler

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 01-31-2012, 05:37 PM
Jonathan Hudson
 
Default Bash substrings – just can’t figure it out…

On Tue, 31 Jan 2012 12:31:06 -0600, Cybe R. Wizard wrote:

>On Tue, 31 Jan 2012 19:07:20 +0100
>Johnny Rosenberg <gurus.knugum@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?

That it's a string substitution, not a glob or wildcard match.
Try

$ echo ${File//N*s}



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 01-31-2012, 05:39 PM
"Cybe R. Wizard"
 
Default Bash substrings – just can’t figure it out…

On Tue, 31 Jan 2012 12:31:06 -0600
"Cybe R. Wizard" <cybe_r_wizard@earthlink.net> wrote:

> On Tue, 31 Jan 2012 19:07:20 +0100
> Johnny Rosenberg <gurus.knugum@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.

Cybe R. Wizard
--
Strength through Unity.
Unity through faith.
Adam Sutler

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 01-31-2012, 06:13 PM
Jonathan Hudson
 
Default Bash substrings – just can’t figure it out…

On Tue, 31 Jan 2012 19:55:24 +0100, Johnny Rosenberg wrote:

>2012/1/31 Jonathan Hudson <jh+ubuntu@daria.co.uk>:
>> On Tue, 31 Jan 2012 12:31:06 -0600, Cybe R. Wizard wrote:
>>
>>>On Tue, 31 Jan 2012 19:07:20 +0100
>>>Johnny Rosenberg <gurus.knugum@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?
>>
>> That it's a string substitution, not a glob or wildcard match.
>
>What's a ”glob”? English is not my native language, sorry. I try the
>best I can though.
>
>> Try
>>
>> $ echo ${File//N*s}
>
>That worked, but somehow I still don't understand exactly why my
>example didn't… *confused*
>
>
First ## is a glob (pattern match), apologies. The reason why your ##
doesn't work is because (a) it is the prefix match, not a suffix match
and (b) it tries to match the whole remainder of the string (which ends
in 'c', not 's), whilst // is a replacement.

$ echo ${File%%N*c}

illustrates the suffix (end bit) match.

and

$ echo ${File##03. }

shows the prefix match.

-jh






--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 05:27 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org