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 11-22-2009, 04:18 AM
Ray Parrish
 
Default Escaping quote marks

Nils Kassube wrote:
> Ray Parrish wrote:
>
>> Wow Nils, now if I could just understand what your code is actually
>> doing.
>>
>
> Here's an explanation:
>
>
>>> while test "$ThisLine" != "${ThisLine#* }";do
>>>
> We loop until "$ThisLine" is the same as "$ThisLine" with the first part
> of the string including the first space is removed, i.e. until there is
> no space in the string. We replace one space at a time, so we need a
> loop.
>
>
>>> x="${ThisLine#* }"
>>>
> "$x" becomes the end of the string after the first space.
>
>
>>> y="${ThisLine%$x}"
>>>
> "$y" becomes the start of the string with "$x" removed at the end, i.e.
> the start of the string up to (and including) the first space.
>
>
>>> ThisLine="${y% }%20$x"
>>>
> Concatenate "$y" without the space at the end, "%20" and "$x".
>
>
>> I did solve the problem with a function and word expansion. I
>> pass each line to a function that receives the line as a parameter.
>> If there are spaces in it, it gets treated like several command line
>> parameters.
>>
>
> That will probably work here because it is unlikely that your URLs have
> several spaces in sequence. However if you recycle your code (like my
> code above was taken from a script I wrote long ago) it may not work in
> the new context.
>
>
> Nils
>
Hello again,

Thanks for the commented code this time. I'm still fuzzy on the meanings
of the things like #, and % in your code, but I get the general idea of
what is going on. Could you elaborate a bit? Sorry 8-)

About my code and multiple spaces... wouldn't bash just ignore extra
spaces between command line arguments? I would think it would still
work, but I'm no expert. 8-)

Later, Ray Parrish


--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com




--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-22-2009, 08:52 AM
Nils Kassube
 
Default Escaping quote marks

Ray Parrish wrote:
> Thanks for the commented code this time. I'm still fuzzy on the
> meanings of the things like #, and % in your code, but I get the
> general idea of what is going on. Could you elaborate a bit? Sorry
> 8-)

From [1]:

| ${parameter#word}
| ${parameter##word}
| The word is expanded to produce a pattern just as in filename
| expansion (see Filename Expansion). If the pattern matches the
| beginning of the expanded value of parameter, then the result of the
| expansion is the expanded value of parameter with the shortest
| matching pattern (the ‘#’ case) or the longest matching pattern (the
| ‘##’ case) deleted. If parameter is ‘@’ or ‘*’, the pattern removal
| operation is applied to each positional parameter in turn, and the
| expansion is the resultant list.

And similarly ${parameter%word} deletes at the end of the string.

> About my code and multiple spaces... wouldn't bash just ignore extra
> spaces between command line arguments? I would think it would still
> work, but I'm no expert. 8-)

Yes, bash would ignore the extra spaces and that would change the final
URL. If the original URL included "some text" (2 spaces) it should be
"some%20%20text" after encoding but with your code it would be
"some%20text". Anyway, it probably doesn't matter because it is unlikely
that your map URLs include double spaces. Just be careful if you use the
same code for something different.


Nils

[1] <http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion>

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-22-2009, 10:26 AM
Ray Parrish
 
Default Escaping quote marks

Nils Kassube wrote:
> Ray Parrish wrote:
>
>> Thanks for the commented code this time. I'm still fuzzy on the
>> meanings of the things like #, and % in your code, but I get the
>> general idea of what is going on. Could you elaborate a bit? Sorry
>> 8-)
>>
>
> From [1]:
>
> | ${parameter#word}
> | ${parameter##word}
> | The word is expanded to produce a pattern just as in filename
> | expansion (see Filename Expansion). If the pattern matches the
> | beginning of the expanded value of parameter, then the result of the
> | expansion is the expanded value of parameter with the shortest
> | matching pattern (the ‘#’ case) or the longest matching pattern (the
> | ‘##’ case) deleted. If parameter is ‘@’ or ‘*’, the pattern removal
> | operation is applied to each positional parameter in turn, and the
> | expansion is the resultant list.
>
> And similarly ${parameter%word} deletes at the end of the string.
>
>
>> About my code and multiple spaces... wouldn't bash just ignore extra
>> spaces between command line arguments? I would think it would still
>> work, but I'm no expert. 8-)
>>
>
> Yes, bash would ignore the extra spaces and that would change the final
> URL. If the original URL included "some text" (2 spaces) it should be
> "some%20%20text" after encoding but with your code it would be
> "some%20text". Anyway, it probably doesn't matter because it is unlikely
> that your map URLs include double spaces. Just be careful if you use the
> same code for something different.
>
>
> Nils
>
> [1] <http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion>
>
Hello again,

I've been reading that doc in the link you posted, and I had a question.
From what I am reading the following would replace all spaces in a
string with %20

ThisLine=${ThisLine/ /%20}

Am I correct in my understanding of this syntax?

Thanks, Ray Parrish

--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-22-2009, 11:20 AM
Nils Kassube
 
Default Escaping quote marks

Ray Parrish wrote:
> Nils Kassube wrote:
> > <http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-
> >Expansion.html#Shell-Parameter-Expansion>

> I've been reading that doc in the link you posted, and I had a
> question. From what I am reading the following would replace all
> spaces in a string with %20
>
> ThisLine=${ThisLine/ /%20}
>
> Am I correct in my understanding of this syntax?

No, it will replace only the first space. If you want to replace all
spaces, it would be this:

ThisLine=${ThisLine// /%20}

Of course you don't need a loop with this code. You can even take your
original code and replace just one line:

case "$ThisLine" in
*<loc>*)
URLs="$URLs ${ThisLine// /%20}";;
esac

And thanks for pointing out the ${parameter/pattern/string} parameter
expansion that I wasn't aware of. Actually I hadn't read the entire page
of the link when I was searching for an online reference. Using this
info I can now clean up some old scripts.


Nils

--
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 08:01 AM.

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