of course writing a server of anything in pure bash is a tad bit difficult, as opposed to a client - bash can connect(), but can't bind() / listen() nor accept() unless, of course, you use something to expose these syscalls, but that opens a whole another can of worms...
I think the point here is to demonstrate that one might think that web servers are mystical beasts (true) but after all, they "just" return a HTTP header and some content.
It doesn't demonstrate that very well, then. This simply delegates all of the basic server responsibilities to netcat. Where do you draw the line between 'bash web server' and simply invoking another program?
Many people here fail to realize, this is an excellent debugging server. I used to have a server to print out the body and headers of requests when building an api to make sure things were going (the right headers and request body) out as expected https://github.com/minhajuddin/httpdebug/blob/master/app.go.
This is a much lighter and nicer version. This is going into my ~/bin/httpdebug :)
You can try sending a few curl requests to see that this really prints the headers and body.
curl -H "api-key: Foo" -X POST --form name=Khaja http://localhost:8080/
Bash (shell-script) is a very powerful language, but a bit too complicated for the non-programmer (computer hacker). Then we got Perl, but it is also a bit too complicated. Now we have JavaScript doing the same thing, but also JavaScript (ES6) is now getting more complicated. I wonder is there a rule that says a (scripting) language for non-programmers will eventually either die or end up being too complicated for non-programmers ?
For me the scripting language for non-programmers looks more like Automator (the GUI) or Workflow - its iOS counterpart.
A programming language will always be for programmers or at least enthusiasts.
Also I do not agree that bash is good for non-programmers. In order to make any more complicated thing work you have to learn a lot of syntax and language specific things. I have always found perl easier than bash to do anything remotely more complicated.
A small amount of pessimism is healthy, but something being really simple is often preferable. A key here is good abstraction. Take for example a file system, witch is very easy to use, but still useful for computer experts.
36 comments
[ 4.5 ms ] story [ 87.6 ms ] thread1. hardly a web server
2. hardly pure bash
of course writing a server of anything in pure bash is a tad bit difficult, as opposed to a client - bash can connect(), but can't bind() / listen() nor accept() unless, of course, you use something to expose these syscalls, but that opens a whole another can of worms...
Someone has actually went that far: http://ctypes.sh/.
> Of course not.
It works just fine on Windows 10 with WSL.
This is a much lighter and nicer version. This is going into my ~/bin/httpdebug :)
You can try sending a few curl requests to see that this really prints the headers and body.
> No.
Well, which is it ?
It can only accept one connection at a time because of the netcat command being used in a loop
Well, anyone can write that in a handful of lines in most languages.
A programming language will always be for programmers or at least enthusiasts.
Also I do not agree that bash is good for non-programmers. In order to make any more complicated thing work you have to learn a lot of syntax and language specific things. I have always found perl easier than bash to do anything remotely more complicated.
Not that big.