yes `yes no`


I’ve recently gotten into using the tools that make a Unix system different from a MS-DOS system; the terminal (among others). There’s a lot of very useful tools in GNU’s coreutils package. Among them are ls, cat, kill, rm, and so forth.

On a Mac, try this:
curl | base64 | say

It’s totally useless and totally fun.

What is yes?

Speaking of fun, there’s a really fun command in coreutils called yes.

Here’s a description of yes from manpagez:

yes – be repetitively affirmative

So yes spits out the letter y forever (until stopped). It takes one argument, which will override the output with whatever you want.

An actual use case for this is piping it into an installer or something, to skip all required input during installation of something.

For example, you can run yes michael > ~/Desktop/michael.txt for a while if you want a really large and useless file with just my name over and over again in it.

Unfortunately yes doesn’t accept text piped into it, but it can apparently take another yes’s output command as a parameter:

Don’t do this.
yes `yes no`

This sort of slowed my computer below the threshold of usefulness, so I had to restart it.

What is yes doing, actually?

Taking a look at the source code for yes, it looks like the single argument is being stored in a char array, then, in a while(true) and for loop, each character is printed to the stdout, followed by a new line (\n) character.

So when we use the output of one yes command as the argument for another, the outer yes command fills up the computer’s memory with the output of the inner yes command. Then I have to restart my computer and feel stupid.

Note: A lot of folks pointed out that I was incorrectly explaining what’s happening here. So as I understand it now, the shell runs the contents of whatever’s in the backticks (`) and hands it off the the bash, except it never finishes in this case. Now I don’t really know the difference between shell and bash, but I get that this may be finally a good use for 16GB+ ram.

What is the point of this post?

There’s none. Go home, you’re being judgmental.