Escaping quote marks

Nils Kassube kassube at gmx.net
Sun Nov 22 12:20:16 UTC 2009


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




More information about the ubuntu-users mailing list