Skip to content

Instantly share code, notes, and snippets.

@killdash9
Last active February 26, 2018 01:44
Show Gist options
  • Save killdash9/e073b182aa101aca52625f945ec5ddca to your computer and use it in GitHub Desktop.
Save killdash9/e073b182aa101aca52625f945ec5ddca to your computer and use it in GitHub Desktop.
A minimal HTTP server in bash that listens on port 1234
#!/bin/bash
#Serves the current directory.
test -p .f||mkfifo .f;while :;do cat .f|nc -l ${1:-1234}|(read m u p;echo $u;u=${u#/};{ echo -e 'HTTP/1.0 200 OK\nContent-type:text/html\n';test -d $u&&ls $u|sed "s,.*,<a href=\"$u/&\">&<br>,"||cat $u;}>.f);done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment