an instant web server using netcat

this shell one-liner will launch a simple web server, listening on tcp port 80.

<code> while true do ; echo -e HTTP/1.0 200 OK\r\n\r\nhello world\r\n|nc -l 80 ; done </code>

wrap it in a shell script that will accept an alternate port as a command line argument:

#!/bin/sh
port=${1:-80}
( while true ; do nc -l $port <<EOM
HTTP/1.0 200 OK^M
^M
<html>
<head><title>success</title></head>
<body>hello world.</body>
</html>
EOM
done ) &