Bash

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

Atoms

Number2

Zzz…

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.

Advertisements

2 Responses to Bash

  1. Miorel says:

    The collapsing of extra spaces is not exclusive to echo. The shell does this for all commands.

  2. putnam120 says:

    Guess I need to play around with more commands.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: