Escaping quote marks
Nils Kassube
kassube at gmx.net
Sun Nov 22 09:52:16 UTC 2009
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>
More information about the ubuntu-users
mailing list