26 May 2011
bash - test syntax before execution
Shoulder surfing an experienced shell user always leads to “how did you do that!?” or “oo that’s cool, never tried that before”
So here’s a quick tip I learned a while ago:
Say you want to run a loop to do something with some input, and you want to make sure it’s right before you execute it 100x. Lets take this simple example, make 10 directories named 1..10 each with 10 sub dir’s named 1..10.
To test this we can make the loop, but instead of running the command, echo out the command:
Great, that’s the 100 commands we wanted to run printed to the screen. Now here’s the trick, instead of editing out the echo command just pipe it through your shell:
Volla! You’ve just created 100 dirs.
Want to contribute to this article? Edit this post on Github!