[ale] Partial interpretation in a bash script
David S. Jackson
deepbsd at earthlink.net
Mon Oct 27 12:29:50 EST 2003
On Sun, Oct 26, 2003 at 06:03:49PM -0400 David Corbin <dcorbin at machturtle.com> 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.
>
> What's the correct solution to this?
Have you taken a look at the mozilla startup? It's just a shell
script that has to handle just the case you mention. Unfortunately,
even that script doesn't handle metacharacters, like you'd find in a
complex url, very well at all, unless you quote the whole thing. My
Mozilla 1.5 startup script uses
exec $MOZ_PROGRAM ${1+"$@"}
where $1 and $opt have been tested for a bunch of parameters.
Trouble is, as you mention, when you go
browser http://one.two.three/cgi-bin/whatever.pl?val1=one&val2=two+val1
or something similar, the shell script won't even *see* the arguments
unless you quote the whole thing.
I suspect that both "$@" and "$*" might be getting off on the wrong
foot. You'll probably have to start with "basename $0", then
deconstruct $1 for any commandline options directly to your browser,
then parse everything afterwards for metacharacters for special
handling, or you could just trust its integrity and pass it directly
to the browser like the mozilla startup does.
Not sure there is any *easy* way to handle the metacharacters you're
talking about, like you'd find in a complex url.
PS. "$*" is a single string that consists of all of the positional
parameters separated by the first character in the environment
variable IFS (internal field separator), which is a space, TAB, and
NEWLINE by default. On the other hand, "$@" is equal to "$1" "$2"
... "$N", where N is the number of positional parameters. That is,
it's equal to N separate double-quoted strings, which are separated
by spaces.
-- source: p. 87 of __Learning the Bash Shell__, by Newham and
Rosenblatt, O'Reilly, 1995
--
David S. Jackson dsj at dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Why bother building any more nuclear warheads until we use
the ones we have?
More information about the Ale
mailing list