Friday, September 08, 2017

Bash Racing

Photo by Kenny Milton Freeland (CC BY-NC-DN 2.0) 

(CC BY-NC-ND 2.0)

Every once in a while I play a little game called Bash racing.  You have probably been here before. Working on the command line you create some bastard of a command.  A dozen pipes dumping stuff to the tmp files, hitting the network with curl in the middle, and n^3 in operation.  You could have made it much faster, but you didn't remember how to specify the delimiter for xargs, or the command to remove a range of sections from the line.  But you created it in less than a minute and it is now churning along and will give you results even if it is clearly going to take a while, perhaps even a minute or two.  Just enough time to play bash racing.

Immediately open up a new terminal and start reworking the commands.  The goal is to craft a better command that can deliver the results before the original bash window finishes.  Lookup man pages and skim as fast as you can to learn what you need.  When feeling sadistic toss in pv in the original command so you have a constant clock counting down how much time is left before you lose.

Computers are really fast and so rarely do I win, but when I do win it is a sweet victory.  And like all good games it teaches you something and automatically gets harder the more you play (and easier if you forget things).  The "Ai" you compete against is constantly getting better and stuff you learn in this game will be incorporated into future initial bash commands.

So the next time you see someone sitting there waiting for their bash command to execute ask them to try playing bash racing.

Popular Posts