euglug.org

[Eug-lug] simple script?

작성자

카테고리:



Senior GoatSun Jun 20 20:11:57 PDT 2004

Nice.  I know I've had trouble with arguments spreading out using $@, but I 
must have used some intermediary to take apart the args.  I plugged it into 
a test script and bash did things as expected.

Anyway, URLs can have spaces in them, but they are converted to ascii by 
http speakers.  For example, wget "http://a.com/a b c d.html" is very valid, 
but will ask for, and probably save as a%20b%20c%20d%20.html.

>From: Allen Brown <abrown at peak.org>
>Reply-To: Eugene Unix and Gnu/Linux User Group <euglug at euglug.org>
>To: Eugene Unix and Gnu/Linux User Group <euglug at euglug.org>
>Subject: Re: [Eug-lug] simple script?
>Date: Sun, 20 Jun 2004 19:46:03 -0700 (PDT)
>
>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/
>         allen_brown at agilent.com	            abrown at peak.org
>   The trouble with the rat race is that even if you win,
>   you're still a rat. ---Lily Tomlin
>
>_______________________________________________
>EUGLUG mailing list
>euglug at euglug.org
>http://www.euglug.org/mailman/listinfo/euglug

_________________________________________________________________
MSN Movies - Trailers, showtimes, DVD's, and the latest news from Hollywood! 
http://movies.msn.click-url.com/go/onm00200509ave/direct/01/