Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
One-line bash http server
:;while [ $? -eq 0 ];do nc -vlp 8080 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed 's/[^a-z0-9_.-]//gi'`;h="HTTP/1.0";o="$h 200 OK\r\n";c="Content";if [ -z $f ];then($e $o;ls|(while $r n;do if [ -f "$n" ]; then $e "<a href=\"/$n\">`ls -gh $n`</a><br>";fi;done););elif [ -f $f ];then $e "$o$c-Type: `file -ib $f`\n$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done
@monokrome

This comment has been minimized.

Copy link

commented Sep 6, 2016

This is surely not one line of code as this page suggests.

@Tak-MK

This comment has been minimized.

Copy link

commented Sep 7, 2016

Every ; is a new line, so that's not one line of code...

@Anaphase

This comment has been minimized.

Copy link

commented Sep 8, 2016

Yeah, wtf. Just because something is on one line doesn't mean it's "one line of code". If that were the case then any properly minified file would be "one line of code" lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.