a life of coding

Friday, April 29, 2005

Doing Nothing in Bash

Going on what is probably a record, this is the THIRD post today. Technically, the Ninja post was a draft from a couple of weeks ago, but for the sake of THREE posts in one day, I'm just going to pretend that I wrote it today. And now, on with the post...

What is your favorite way to do nothing in /bin/bash? In C, there is ";" (on a line by itself); in python, "pass". But in bash, how do you go about doing nothing? I know what you are going to ask, so I'll just lay it out there: If there is a while loop, and the condition of the while loop is the result of the command you are executing, then there is nothing to be done in the body. Unfortunately, bash doesn't seem to like this - so, something has to go in the body. Obviously there are many things that can go there, so we should have some metrics for picking one. The first metric, is that doing nothing should be easy. The second, it should be fast. So to this end, here are a few things to try:
  • touch /dev/null [Keystrokes: 15. Runtime: 0.02s]
  • sleep 0 [Keystrokes: 7. Runtime: 0.03s]
  • A=0 [Keystrokes: 3. Runtime: 0.00s]
So far, it looks like A=0 wins. It does have a side effect for the command, but that seems like an easy enough thing to get around.


  • I know this is old, but I think this is what you were looking for:

    while echo something; sleep 1; do :; done

    By Anonymous Wodin, At 12/5/07 8:50 AM  

  • And for completeness:

    : [Keystrokes: 1, Runtime: 0.00s]

    By Anonymous Wodin, At 12/5/07 8:52 AM  

Post a Comment


Create a Link

<< Home