Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> As it turns out, bash can speak HTTP by itself.

No, it can not. Bash lets you open TCP sockets.

What you are doing here is trying to speak HTTP yourself, which is fine for testing and debugging, and hella cool for fun to do by hand, but you will shoot yourself in the foot if you try to use this pseudo http client unattended in reality. This toy code does not parse HTTP properly and will break.

You could of course write a full http/1.1 client in bash, you can even do a full http server in pure bash: https://github.com/bahamas10/bash-web-server

For less insane, non-bash shells there is always nc which is usually probably the wiser choice.



Need to be clear that "full http server in pure bash" is incorrect. Bash cannot listen on a TCP/UDP socket for incoming connections.

bash-web-server project builds a C language socket listener [0] that is dynamically loaded at run-time as a "built-in" module that makes the functionality available.

[0] https://github.com/bahamas10/bash-web-server/tree/main/loada...


This feature has been part of bash since 5.1 (ca 2020), though it may not be enabled in all distros.

  cd src/bash-5.3/examples/loadables
  make accept
  enable -f ./accept accept
  (accept -r RHOST -v SOCKETFD -b 127.0.0.1 8000; 
    read -u $SOCKETFD SOCKETDATA; 
    printf "%s: %s\n" "$RHOST" "$SOCKETDATA";
    printf "goodbye, world\n" 1>&${SOCKETFD} ) &
  nc 127.0.0.1 8000 <<< "hello, world"
For real use you may need to add "exec {SOCKETFD}<&-" to close the FD.

Edit: https://news.ycombinator.com/item?id=39369749 (2024)


By this logic, Linux does not support Wi-Fi, because all the driver modules are "dynamically loaded at run-time."


No, by any other logic you can implement your Wi-Fi drivers in bash.


Pure Linux doesn't.


Interesting. I have never heard kernel modules being regarded as non-linux, not in 30 years of LKM. Further compiling a monolithic Kernel is rather straight forward, in this day it is even possible to find wifi devices that do not require a an on device firmware blob uploaded from the kernel.


Same, this whole thread is like the twilight zone for me... I can't tell if I'm losing my mind or all the people with this way of thinking are just being completely unreasonable but I've never seen several people at once agree with such a ridiculous (to me) comment.

Reminds me of the time on libera IRC when someone told me "cloud storage does not exist" because they were hung up on some ultra-purist word definition that nobody else shared.


I don't know TBH. It's just that if you're going to have a 'pure' designation for a tech, it's going to be pretty strict (as per bash and adding modules). I've never heard of 'pure' linux, but 'pure' bash has a recognised meaning. If someone said 'pure Linux' and it meant the core without loaded modules I wouldn't be shocked. Not sure how useful it would be, though.


> If someone said 'pure Linux' and it meant the core without loaded modules I wouldn't be shocked. Not sure how useful it would be, though.

That probably wouldn't be a useful distinction because almost every module can be built in


Correct. It doesn't.


> No, it can not. Bash lets you open TCP sockets.

Very fair pushback -- I did get carried away and will update the article to be more precise. Thanks for raising it!

> For less insane, non-bash shells there is always nc which is usually probably the wiser choice.

For completeness, `nc` or any netcat equvialent I could think of was not available in the image I was trying this with. It would certainly be a better option though.


This is the most Claude pilled comment I've seen here.


This worries me. Some AI writing styles became mainstream; at first it was the em-dashes, now it’s “A, not B” patterns and excessive acknowledging. There will be more.

Was grandparent comment written by an LLM?

Or is this a human who copies a style they saw in a blog post, unaware that they’re copying an AI?

Or is this a human who spent too much time talking to an AI and now they just talk like this?

Or is this an organic human response and we’re all paranoid by now?

I don’t know which would be worse.


When learning a language, I've heard it's good to find a reference speaker, such as a prolific actor, and mimic them in order to absorb several aspects of what makes them sound authentic as a speaker, such as vocabulary, intonation, diction, pacing.

For many in the next generation of language learners, this reference will be Claude.


I think that the fact that AI has a very recognizable singular style is a problem. And this problem will be solved, sooner or later. It probably isn't a very important problem, because I feel that it should be relatively easy to solve (but maybe I'm wrong?).

But certainly with smarter AI I do believe it'll become more fluent with choosing more diverse idioms and phrasing, rather than repeating one thing over and over, to a point of being a comically similar. So people who learn on AI-generated text, will not learn from just one recurring style.


> It probably isn't a very important problem

The amount of languages are decreasing on the earth, I would also say that dialects and accents are decreasing as well. I think this is a problem.


Insightful, and scary! Imitating an imitation machine... even if no one is trying to intentionally do so, McLuhan's "we become what we behold" is inescapable.


I'm going to go insane from all of this


So? That's literally how language works. The importance is not in the writing style, but in the content of the words.


Those are not separate things.


It's pretty rough to learn I sound like Claude. Will need to do something about it then.

(For what it's worth I did write the message above manually but I understand why no one would believe that now. At least I did not call netcat "load-bearing" [https://mareksuppa.com/til/load-bearing/] or something...)


I did not think you sounded like claude. Then I looked again after the comment was made and then I saw some of the vibes. Like acknowledging a mistake you have done.

Before that would just made you top 5% (or maybe top 1%) of the nicest people to talk too.. know ppl think you are Claude.

We are all going crazy s a sibling comment said.


It's wasn't "acknowledging the mistake" it was the phrasing and general structure while doing so.


I know that feeling

I notice myself getting afflicted with llm-isms after a full workday. And I didn't always notice, sometimes I only realize the day after...

Like it slowly siphoned out my soul, which then reconnected with me over night


Avoid the backtick quotes, too. Claude also mistakenly uses them outside of markdown.


Ok Claude :)


I’m torn. It’s a great thing to share knowledge and take feedback graciously. Maybe this kind of comment will encourage more of that. But you also need people to tell you what is up without unnecessary filters. It’s a challenge


what would be a non-pilled way of saying the same thing?


Yeah. The comments saying it's AI-pilled comments are more annoying and less informative than the comments themselves.


Agreed. I really wish Dang would explicitly add that to the rules.


Good point however netcat wasn’t available either.


FWIW, I didn't read this as AI-like. Even on a re-read, it's only the quasi-em-dash, and _maybe_ the polite acknowledgement of "Very fair pushback" (just good etiquette, IMO!) that would ring any alarm bells. You're fine.


Not to mention, the typo in the word "equivalent".


[flagged]


An old habit that unfortunately makes one indistinguishable from LLMs these days...


I have done the same for many years now, and I feel like it's going to be an annoying false positive for people like us.

I remember when the "hacker vs. cracker" distinction went away because Hollywood co-opted the former and it became de facto "hacker == bad guy"


>No, you can't write 10 lines of code, you have to import a 100k LOC dependency

Common misconception, if you want to replace a dependency on a swiss knife you don't need to implement a swiss knife, sometimes you can just implement the last helix of the corkscrew.


it's curious what you'd be building where you think you can hit the reliability of curl with a bash script.


health check, check that website/webapp returns 4xx and some known keyword

api, GET url, content-type aplication/json, parse json

you can even invert it and make a server


a script ten lines long perhaps?


it's not that insane. i've been manually typing http requests in since before http/1.1 and the mandatory host header.

it is insane to use it for anything serious (also the opposite, implementing webservers in bash), but for quick testing it's pretty great!


Why wouldn’t you use curl for the quick test?


Sometimes you want to do something that curl cannot express, e.g. timing, protocol oddities, etc. For example you may want to issue a CONNECT to an echo server through a proxy and observe the bytes flowing back and forth. You may want to see what happens when conflicting hop-by-hop headers are specified without worrying about the client's (curl's) interpretation of them. A simple nc -c (or openssl s_client -crlf) lets you do all of that.


For what it's worth curl can do very detailed timing [1] and it can also do this using a proxy

    export http_proxy=http://your.proxy.server:port/

    export HTTPS_PROXY=https://your.proxy.server:port/

    curl -x http://proxy_server:proxy_port --proxy-user username:password

    or  $socks-wrapper curl # [2]
[1] - https://dev.to/gbhorwood/curl-getting-performance-data-with-...

[2] - torsocks, tsocks, wireproxy, shadowsocks-rust, proxychains-ng, etc...


what I meant was a proxy that implements HTTP/1.1 CONNECT

and a server behind it like

``` mkfifo /tmp/myfifo cat /tmp/myfifo | nc -l 12345 > /tmp/myfifo ```

so if you manually type out

  CONNECT host:12345 HTTP/1.1
  host: host:12345

you can see exactly what's happening. To be fair you can hack curl to support that via

  curl -x proxy:3333 telnet://host:12345
but that's not exactly what you want and requires curl to have been compiled with telnet support.


Ah, I see what you mean. Aside from putting the proxy into debug logging one would have to use curl -vvv to get similar details but I suppose whatever works best with muscle memory is the right choice and one may not always have access to put the proxy into debug logging.

I need to try this with a Squid SSL Bump MitM proxy just dont have one up at the moment.

    curl -vvv -A Mozilla -H "Accept-Language: en_us" -H "Sec-Fetch-Mode: navigate" --url 'https://nochan.net/.env'


because in those days there was no curl, or wget. and then when there was, there was no guarantee they'd be installed.

telnet was always there though. it also worked for speaking all the other plaintext internet protocols. (imap, pop, smtp, etc)


Note: Telnet is not completely plaintext and has control characters in the upper byte range (like 0xff or something, I forget).

Use nc or this TCP Bash technique if you really want to ensure decent compatibility when doing hacky solutions, otherwise a random 0xFF somewhere from a terminal console color change (or other control character) might really screw you over.

EDIT or ya know, use the correct tool like Curl.


I used telnet to send mail via SMTP once, it's quite literally a good social protocol because it begins with a polite 'HELO'.


Is it the reply to ‘HELO’ that enables things like tarpits?

Like if my server replied with ‘HI PLEASURE TO MEET YOU 127.0.0.1 THAT NAME SOUNDS FAMILIAR ARE YOU BY CHANCE FROM BOSTON MY MOTHER IS FROM BOSTON WELL QUINCY ACTUALLY BUT DO YOU KNOW 127.0.1.1 THEY ARE A REALLY GOOD FRIEND OF MINE YOU SHOULD MEET I HEAR THEIR DAUGHTER IS A DOCTOR DONTYAKNOW AND YOU COULD…”

etc, etc?


For SMTP tarpits you can do all kinds of fun stuff. Not just in the reply to helo. Like: always be slow to respond. Respond to each command with a temporary error. Accept everything, then pause, then error. Send back large chunks of garbage.


the '90s version of finding the hiring manager or boss on linkedin to try and get a job was connecting to the company's public smtp server with telnet, using their name to probe different email address patterns with "rcpt to:" (those days the actual servers were often directly connected to the internet and would leak email address validity in how they would respond to rcpt to) and then sending them a nice email.

smtp grew up to be an antisocial curmudgeon. extended smtp starts with EHLO.


> smtp grew up to be an antisocial curmudgeon. extended smtp starts with EHLO.

email will become so unusable, next one will have to be HELNO i guess


> smtp grew up to be an antisocial curmudgeon. extended smtp starts with EHLO.

"EHLO" still sounds friendly. It just sounds like a different accent or something. Know someone that used to answer calls with a friendly "Jello?".


Eventually Microsoft will debut Microsoft Extended SMTP which will greet with MEHLO


yeah, i think you're right. i originally read a bit of snarky blow-off, like "eh?" ... but you know, now that i think of it, it's actually does have more of a friendly canadian style vibe.


In the days of ultra thin containers, there's still no guarantee curl or wget will be installed, either.


Because curl is not installed in minimal docker images.


Sometimes I don't understand why people use those most tiny of images, at least for anything that they might ever ssh into.

When there is no corresponding level of restraint in the libraries that we add to most applications, does it really make a difference to leave out the likes of curl, nano, ping, etc compared to how frustrating it is to operate in just busybox (etc)?

I'm not just ranting, I'd actually like someone who swears by always shipping alpine images (etc) and never installing any basic utilities in them to share their reasoning.


Less installed things means smaller security surface area, fewer things to patch when CVEs get discovered etc.

Thanks to `kubectl debug`, you don't need to install debugging utilities into your production image.


neither is bash or even sh for that matter :) if you have bash, you probably have apk or apt


Sometimes I worked in environment that blocks all internet access, but I still need some way to test internal connectivity.


I just want to note that HTTP only existed 5 years without curl or wget.


Someone did a Minecraft server in pure bash.

https://sdomi.pl/weblog/15-witchcraft-minecraft-server-in-ba...


It’s impressive but it’s not “pure bash”. Even just in the first section, the author talks about using hexdump and dd.

Though I did also notice they didn’t claim it was pure bash themselves. That’s a flare you added.


There's even a Rails-like framework for Bash: https://github.com/jneen/balls


Nice parameter expansion examples in that bash-web-server. It uses the $_ parameter in ways I hadn’t thought to before, often preceded by a single : ${x} line for pre-processing of the variable.


> No, it can not. Bash lets you open TCP sockets.

I thought you had to use a program called netcat for that--if not then what is the point of that binary? And for that matter, can't you also use telnet to manually send HTTP?


nc is basically just a nicer interface for the same thing, in the same way that curl is.

https://linux.die.net/man/1/nc




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: