Escaping quote marks

Ray Parrish crp at cmc.net
Sun Nov 22 05:18:15 UTC 2009


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







More information about the ubuntu-users mailing list