Skip to content

Instantly share code, notes, and snippets.

@Sitwon
Created January 3, 2014 19:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sitwon/8244641 to your computer and use it in GitHub Desktop.
Save Sitwon/8244641 to your computer and use it in GitHub Desktop.
A very basic replacement for wget in pure Bash.
#!/bin/bash
wget() {
local PROTO=${1%%://*}
local NOPROTO=${1#*://}
local HOST=${NOPROTO%%/*}
local PORT=${HOST#*:}
[ "${HOST}" = "${PORT}" ] && PORT=80
HOST=${HOST%:*}
local URI=${NOPROTO#*/}
[ "${URI}" = "${NOPROTO}" ] && URI=
URI="/${URI}"
(
exec 3<>/dev/tcp/${HOST}/${PORT}
echo -e "GET ${URI} HTTP/1.1\r\nHost: ${HOST}\r\nConnection: close\r\n\r\n" >&3
cat <&3
)
}
if [ "${BASH_SOURCE}" = "${0}" ]; then
wget "${@}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment