Live data from Hacker News

Test your square brackets

fluca1978.github.io

51–60 of 68 posts

Re: Test your square brackets

#51
I knew that `[` was notionally the same as `test`, but had never 'checked'. I just assumed `[` was a built-in that conformed rather than them actually being the same.

So I very much enjoyed following along with the article, first seeing that `ls -il /bin/test` and `ls -il /bin/[` are at different inodes, then md5summing and seeing they are different, getting concerned, then the article revealing that is the case now (I'm trusting rather than verifying about the separate builds).

I was then very satisfied to recall that `[[` is a built-in (as `[[` isn't portable between all shells).

Re: Test your square brackets

#52
post #21

Reminds me of my rather memorable introduction to special characters invoking functions, seeing this dastardly little quip in the email signature of someone in a mailing list (circa '95 or so). :(){:|:&};: My curiosity piqued, I pasted it into the shell on my terminal in a pure example of FAFO. The poor little Sparc 5 I was using ground to a halt over the course of about ten seconds. The reboot was as hard as the les…

I have this printed on a sweatshirt - it saddens me a little that people who get it are so few and far between these days :'(

I have it on a tshirt. Pretty sure most people think it's just an emotional rant in emoji form.

Re: Test your square brackets

#53
post #40

Earlier quoted context omitted.

> The reboot was as hard as the lesson. I'm confused. What happened on reboot?

A hard reboot is where the power goes all the way off, a soft reboot is where it doesn't. A fork bomb makes it very hard / impossible to trigger a soft reboot, forcing you to do a hard reboot. As an extra sting, a hard reboot can be damaging if the software and hardware is not correctly handling power interruption, which was much more likely in the 90's.

Yeah the days before journaling filesystems, a moment to consider your actions as fsck did its best to clean up the mess you made.

Re: Test your square brackets

#54
post #21

Reminds me of my rather memorable introduction to special characters invoking functions, seeing this dastardly little quip in the email signature of someone in a mailing list (circa '95 or so). :(){:|:&};: My curiosity piqued, I pasted it into the shell on my terminal in a pure example of FAFO. The poor little Sparc 5 I was using ground to a halt over the course of about ten seconds. The reboot was as hard as the les…

Context: https://www.cyberciti.biz/faq/understanding-bash-fork-bomb/

And especially the ulimit command mentioned, which is mostly unknown to folks nowadays, it seems.

Re: Test your square brackets

#55
post #15

Earlier quoted context omitted.

Hmm. What if we replaced the whole of bash with the contents of /bin?

…you always need some sort of shell to call the binaries, don’t you? I do think it makes sense to have beginners use `sh` instead of `bash`.

Oh, "once upon a time" I did set emacs to be my login "shell" and emacs can call other binaries via execve, handle sub processes, etc. Worked as expected.

Getting a Linux or Unix system to boot without a proper shell would be another complication, so a system completely without a she'll? I expect that to either be easy nor useful.

Re: Test your square brackets

#56

Earlier quoted context omitted.

It doesn’t have anything to do with bash (though modern bash may use a built in for `[`). He don’t have the `[` program (usually linked to `test`).

Which is why later versions of bash have a builtin… Precisely because those older systems didn’t link to it! So my comment still stands.

> Precisely because those older systems didn’t link to it!

Not to speed up bash scripts? Launching a process for simple if statements such as those checking whether a file exists is fairly expensive.

Re: Test your square brackets

#57
post #21

Reminds me of my rather memorable introduction to special characters invoking functions, seeing this dastardly little quip in the email signature of someone in a mailing list (circa '95 or so). :(){:|:&};: My curiosity piqued, I pasted it into the shell on my terminal in a pure example of FAFO. The poor little Sparc 5 I was using ground to a halt over the course of about ten seconds. The reboot was as hard as the les…

Something I never understood about this: is the pipe necessary, or just to have another symbol contributing to the mayhem?

    :(){:&;:};:
This is the same number of characters but doesn’t use a pipe, and I was never able to figure out why it seems so universally to use a pipe.

Re: Test your square brackets

#58
post #56

Earlier quoted context omitted.

Which is why later versions of bash have a builtin… Precisely because those older systems didn’t link to it! So my comment still stands.

> Precisely because those older systems didn’t link to it! Not to speed up bash scripts? Launching a process for simple if statements such as those checking whether a file exists is fairly expensive.

Ugh, which is why it became a builtin…

Ya’ll are tracing the same logic of the 90s here.

Re: Test your square brackets

#59

In college I took a database class, it was pretty basic overall as I had been playing with MySQL for a few years at that point. On the final exam I got a 90/100. The test was 10 questions that just had you write SQL to answer the question. I got all the queries 100% correct... except... I didn't put a ";" after each query. On a written test. I'm still a little bitter about that.

I had a course on natural language processing with Prolog, and the first third of the exam was just evaluating Prolog expressions and figuring out what syntax errors had been made. This of course took so long that everyone spent at least two thirds of the time on that one portion...

It was a weird course, though. Because we spent so long learning Prolog, the second half of the course was really rushed - lots of learning about English grammar and syntax trees, and how you could model them in different ways, and then the last lecture was just "oh, by the way, here are all the ways this doesn't work and is a complete dead end - your exam is on the 14th".

IIRC there was a part two to the course, but I think it clashed with something I was more interested in so I never took it. It was cool to learn Prolog, but I wish it had been a whole course on just Prolog and actual present-day use-cases, as opposed to this weird half-and-half course about an approach to NLP that even back then wasn't being pursued with much enthusiasm.

Post reply on HN