#!/bin/bash wfetch() { HOST=$1 FILE=$2 PORT=$3 [ -z "$PORT" ] && PORT=80 # Connect to server exec 3<>/dev/tcp/$HOST/$PORT # Send command to server echo -en "GET / HTTP/1.1\r\nhost: http://$HOST/$FILE\r\nConnection: close\r\n\r\n" >&3 # Get response cat <&3 # Close socket exec 3>&- } wfetch www.google.comThis is cool but I would still recommend wget for a production script that fetches web pages. For starters, wget follows redirects unlike this script.
Computer Tips - Can I use pure bash to download a webpage?
Date: 2009oct1
OS: Linux
Language: bash
Q. Can I use pure bash to download a webpage?
A. Yes, use /dev/tcp
More on Using Bash's Built-in /dev/tcp File (TCP/IP)
http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip
Everything is a file!
Putting together all the comments from that page we get: