Friday, September 6, 2013

Web server in bash

Here is a one-line minimal web server written in bash using nc.  It works on the mac, but your mileage may vary on other operating systems which have different flavors of nc. It serves files from the current directory. Enjoy!
mkfifo /tmp/fifo;while :;do cat /tmp/fifo|nc -l 1234|(read m u p;cat <(printf "HTTP/1.0 200 OK\r\n\r\n") .$u>/tmp/fifo;echo $u);done

No comments: