[ale] Partial interpretation in a bash script

Bjorn Dittmer-Roche dittmeb at mail.rockefeller.edu
Sun Oct 26 21:00:01 EST 2003


On Sun, 26 Oct 2003, David Corbin wrote:

> I use a script to launch my browser.  I pass all the arguments to the script
> on to the actual browser, using $*.  Naturally, some arguments (URLs) contain
> special symbols (like &) that the shell wants to interpret, but I don't want
> them interpreted.  Specifying the $* in double-quotes ("$*") doesn't prevent
> intpretation.  Using single-quotes should prevent the expansion of $* (though
> I haven't tested it.

The problem is that special charaters are interpreted by the calling
shell, as well as the shell that is actually running the script. You can
only avoid the latter, not the former. IE. typing

$ script \\\\

will put \\ into the variable $@ (or $*, which I think is the same thing).
$@ my get further interpreted as \, depending on what you do, but there is
very little you can do in your script to keep the original \\\\ from
getting mangled since it comes already mangled by the shell you were using
on the command line. That means the shell running the command never sees
\\\\, so there is no way for it to get it back. (the best you could do is
try to reverse interpret what was typed, which would be error prone if not
impossible).

>
> What's the correct solution to this?
>

I think what you want is to envoke your script with arguments in single
quotes, like this:

$ script 'http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=bash+scripting&btnG=Google+Search'

this worked fine on my simple test script wich consisted of:

| #!/bin/sh
|
| echo $@

bash may be different, but it's supposed to be compatible with sh.

my output was:

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=bash+scripting&btnG=Google+Search

Perhaps there is another shell out there that doesn't interpret funny
chars, but such a shell wouldn't be terribly useful.

	bjorn



More information about the Ale mailing list