Escaping quote marks

Nils Kassube kassube at
Sat Nov 21 07:20:21 UTC 2009

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 

> >           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.


More information about the ubuntu-users mailing list