Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Paul Buchheit: Webserver written in bash - under 20 lines of code (paulbuchheit.blogspot.com)
12 points by mattjaynes on April 14, 2007 | hide | past | favorite | 4 comments


Nice hack.

"And not using perl or any of that fancy stuff"

I think netcat counts as fancy stuff.

Here's the example scripts netcat is packaged with: http://darwinsource.opendarwin.org/10.3/netcat-4/netcat/scripts/

Powerful little tool.


Thanks. Nc is a little bit fancy, but nothing compared to perl. It's also installed by default on both linux (my linux, anyway) and osx. However, the nc installed on OSX doesn't have the "-e" "gaping security hole" option compiled in, meaning that those example scripts (or at least the one I looked at) won't work.

I do wish that there was some way to do this without nc though. Maybe the linux proc filesystem enables net access? Oh well, another day...


You're right, network sockets should be part of the filesystem. Arnold Robbins, author of GNU awk, is a fan of Plan 9 which did this the right way. It was probably the motivation for him adding special files to awk, e.g. "/inet/tcp/0/localhost/17921".

$ nc -l -p 17921 &

[1] 31333

$ date | awk '{print NR, NF [greater than sign]"/inet/tcp/0/localhost/17921"}'

1 4

[1]+ Done nc -l -p 17921

$

http://www.gnu.org/software/gawk/manual/gawkinet/gawkinet.html has more examples. Perhaps there's a FUSE module which gives us a network sockets filesystem?

Cheers, Ralph.

P.S. It's annoying that posters should waste their time probing the mark-up's flaws. Is there a description of it anywhere, e.g. what characters vanish, or how to break lines?


What if you were to run under inetd or djb's tcpserver?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: