1. Getting started

echo

Let’s start with the traditional computer science greeting. Type the following line after the prompt $ in your terminal:

$ echo Hello World

Right beneath your input line you should see:

Hello World

In the line you typed, echo is the command, anything that follows are the arguments. The command and each argument are separated by spaces. Arguments that contain a whitespace internally can be quoted with "", allowing us to pass a single argument to echo, where we passed two arguments before:

$ echo "Hello World"
Hello World

It makes no difference here, but will become important when dealing e.g. with whitespaces in filenames.

Compare the output you get from the following commands:

$ echo "Hello \n World"
Hello \n World
$ echo -e "Hello \n World"
Hello
 World

The argument -e has modified the behaviour of echo. By convention, arguments that begin with - or -- are used to modify the behaviour of a command, they are called command line options or switches.

After looking at the next section, come back here and try out other \... combinations with -e.

Note

We’ll not mention this explicitly again, but you should always go back over previous commands and try to use what you have found out later on. It is possible to race through the examples in a few minutes, but you’ll learn a lot more if you spend time exploring!

man

To find out what happened there with the -e switch, we can look at the manual pages for echo:

$ man echo

To exit the manual page, press q.

Most commands have a man page, and they always follow the same layout: a short statement about the command on top, then a summary showing required and optional arguments, followed by a list of the switches. Man pages for more complicated commands will also include examples of common situations.

Man pages contain a lot of information, you do not have to understand all of it to find what you need!

Now try out some of the options of echo.

Always take a look at the man pages for the commands we introduce from now on, such as man itself:

$ man man