On Mon, 21 Jun 2004, Peter Bailey wrote: > Ha! This is good. > > Unfortunately, I think they're all just a little broken. First off, > if you protect $@, things won't work right. "$@" means all > arguments inclusive, so all the arguments will be treated like > one big one: > > wget "http://a.com http://b.com"
Not correct. "$@" is handled as a special case by the shell. (True for bash and ksh.) Each element on the command line becomes one element at the insertion point. What this means is that you can have strings with blanks in them if they are quoted on the command line. In general "$@" is the Right Way to write scripts. In this case, it probably doesn't matter since I don't think blanks are legal in URLs. But it is better to maintain good programming habits, so that argues for using "$@" even where it is moot. So if you were to type $ myscript "a b" c this would be equivalent to $ wget -r -l1 -nc --no-parent -A.pk3 "a b" c > This is not what you want. > > wget "http://a.com" "http://b.com" > > is what you want. So, how to do that, or: > > wget "http://a.com" > wget "http://b.com" > > and even > > wget "http://a.com/this is a link with spaces" > wget "http://b.com" > > Try this one: > > while [ $# -ne 0 ]; do wget r -l1 -nc --no-parent -A.pk3 "${1}"; shift; done > > > Keep in mind that this only takes arguments when protected by the shell: > > ./myscript.sh "http://www.com/this is a link" "http://a.com" > "http://whatever.com/~!$ADSDF" > > and it will fail in the case of > ./myscript.sh http://www.com/this is a link > > because it thinks of them all as individual arguments. > > > Mr O wrote: > > >This what I have: > >#!/bin/sh > >wget -r -l1 -nc --no-parent -A.pk3 > > This is what you want. > > #!/bin/sh > wget -r -l1 -nc --no-parent -A.pk3 "$@" > > That will let you pull several sites in the same > command. > > ./myget.sh http://site1/foo http://site2/bar http://site3/baz > > If you're tired of typing "http://", you could do this instead. > > #!/bin/sh > wget -r -l1 -nc --no-parent -A.pk3 "http://$1" > > ./myget.sh site1/foo > ./myget.sh site2/bar > ./myget.sh site3/baz -- Allen Brown work: Agilent Technologies non-work: http://www.peak.org/~abrown/ [EMAIL PROTECTED] [EMAIL PROTECTED] The trouble with the rat race is that even if you win, you're still a rat. ---Lily Tomlin _______________________________________________ EUGLUG mailing list [EMAIL PROTECTED] http://www.euglug.org/mailman/listinfo/euglug
