Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: pure zsh implementation of wget



On Sep 24,  9:49am, Guido van Steen wrote:
}
} One more question: How should I modify that snippet to download a
} random url, such as like
} http://security.debian.org/pool/updates/main/i/isc-dhcp/dhcp3-client_4.1.1-P1-15+squeeze3_all.deb

I think you mean "arbitrary" rather than "random"?

Which in turn means you want to parse the URL.  A quick way is probably

  IFS=/ read scheme empty server resource <<<$theurl

which leads to

zwget() {
    emulate -LR zsh
    local scheme empty server resource fd
    IFS=/ read scheme empty server resource <<<$1
    case $scheme in
    (https:) print -u2 SSL unsupported, falling back on HTTP ;&
    (http:)
	zmodload zsh/net/tcp
	ztcp $server 80 && fd=$REPLY || exit 1;;
    (*) print -u2 $scheme unsupported; exit 1;;
    esac
    print -l -u$fd -- \
	"GET /$resource HTTP/1.1"$'\015' \
	"Host: $server"$'\015' \
	'Connection: close'$'\015' $'\015'
    while IFS= read -u $fd -r -e; do; :; done
    ztcp -c $fd
}

You can probably work out how to support ftp: using the zsh/zftp module.



Messages sorted by: Reverse Date, Date, Thread, Author