Corrected notes on the feeding of yes to yes

Discuss

7 Responses to “Corrected notes on the feeding of yes to yes

  1. xzzy says:

    yes | xargs -n 1 -P 0 yes 

    Might be a little closer to what the original author was after, but it won’t crash your system. A ctrl-c will recover things, but anyone else on the system who tries to do anything will get a bunch of “resource unavailable” errors.

  2. nixiebunny says:

    Why is the page not displaying the backtick as a backtick, but as an apostrophe? 

    • billstewart says:

      Yeah, it really makes a difference. 
      yes ‘yes no’ will just print
          yes no
      a lot of times. 
      yes `yes no` executes the stuff in the backtick, and the shell uses it to build an argument string for the outer yes command. 
      The stuff in the backquotes prints
          no
      an infinite number of times.  In an old-fashioned Unix shell, there’s a limit to how big a command line can be, so the shell would probably accumulate the first 1023 or so bytes of “no”, maybe strip the newlines, and fork the outer “yes” command with that as input.  Fancier shells may use malloc to build a much larger character string to buffer the infinite amount of “no”, but it shouldn’t bother the operating system any more than any other command that’s leaking memory (but since it’s your shell, it won’t give a prompt back and might not be good at responding to ^C.)

      I tried it with bash, and the shell complained about not being able to allocate more than [some big number] of bytes and crashed.
      Apparently the standard /bin/sh on Ubuntu is dash, and it ran for a while and then complained “Segmentation fault (core dumped)” which is also a pretty classic error message.

    • Miramon says:

      Yeah, this is a big deal. With the wrong quote char, the whole point is lost.

  3. SamSam says:

    We should probably have a correction on the correction, describing which character is a backtick. `

  4. pasq242 says:

    I thought the backticks were being deprecated, anyway.  Shouldn’t the syntax be:
    yes $(yes no)

  5. KWillets says:

    M:   Ah. I’d like to have an argument, please.
    R:    Certainly sir. Have you been here before?
    M:   No, I haven’t, this is my first time.
    R:     I see. Well, do you want to have just one argument, or were you thinking of taking a course?

    …etc…

Leave a Reply