July 10, 2009

Well today I decided to learn Bash.  One of the tutorials (though not all that great) had a pretty good introduction on some terminal commands.  The best job was done with the echo command.  First I’ll show some examples then explain what they each do.

  • echo "hello     world"
  • echo hello     world
  • echo “Number2 Atoms Zzz…” | tr ” ” “\n” | sort

The first line will print “hello      world” to the screen, while the second will print “hello world”. Notice how the extra space disappeared.  This is because the string is not in quotation marks.  The final example will display




This is due the fact that the tr command will replace all the spaces with new lines, then sort will sort them in lexicographic order. I’ll hopefully explain more about tr in later post since it seems that it can use regx. But basically echo prints whatever follows it to the screen. Finally the pipeline, ‘ | ‘, will cause the result of running the previous command to be used as the input for the following command.  This to will be talked about later, mainly because I am tired and am going to end this post now.