Use BASH to download files
cat << 'EOF' > curl.sh
#!/usr/bin/env bash
if [[ -z "$1" ]]; then
echo "Usage: $0 http://host[:port]/path" >&2
exit 1
fi
if [[ "$1" != http://* ]]; then
echo "Only http:// URLs supported (no HTTPS)" >&2
exit 1
fi
url="${1#http://}"
hostport="${url%%/*}"
path="/${url#*/}"
[[ "$url" == "$hostport" ]] && path="/"
host="${hostport%%:*}"
port="${hostport##*:}"
[[ "$host" == "$port" ]] && port=80
exec 3<>"/dev/tcp/${host}/${port}" || {
echo "Connection failed" >&2
exit 1
}
printf "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n" "$path" "$host" >&3
while IFS=$'\r' read -r line <&3; do
[[ "$line" == "" ]] && break
done
cat <&3
exec 3>&-
EOF
chmod +x curl.shLast updated