3  Using the shell

Prior experience

You can skip this section and proceed directly to the exercises if you are already familiar with the basic syntax of Unix commands. We still recommend checking out the tips and hints in Section A.1 and the special syntax overview in Section A.2 though.

3.1 Interacting with the shell

When you launch your (Bash) shell, you will be greeted by what is called a shell prompt: a short snippet of text followed by a cursor, which indicates that the shell is waiting for input. The prompt can look different on different systems, but it often consists of your linux username followed by the name of your machine (like in the picture below) or sometimes just a single $ symbol. When you see the prompt, you can enter commands interactively and execute them by pressing enter.

A bash shell prompt waiting for user input

A bash shell prompt waiting for user input

Already note that you cannot use your mouse cursor to move around your terminal. You will need to use your arrow keys (or shortcuts) to move around while typing commands.

3.2 Command syntax

Unix commands generally follow the format:

command [OPTIONS] argument

where,

  • command is the name of the (usually built-in) command that you want to execute.
  • [OPTIONS] is a list of optional flags to modify the behaviour of the command. They are often preceded by a single (-) or double (--) dash.
  • argument is a thing that your command can use. E.g., it can be a file name, a short piece of text (or string)

Try it yourself with the following command:

echo “Hello world!”

echo is a command that simply prints a message to your screen (technically, to the standard output stream (stdout) of the terminal). echo is the command, teling the shell what we want to do. "Hello world!" is the target, in this case the message we want to print.

We place the message between quotes (") because it contains spaces, and as you will see, spaces (and certain other special characters) can cause confusions. For now, just note that the message that gets printed, is whatever was written between the quotes, but not the quotes themselves.

$ echo "Hello world!"
Hello world!
$

3.3 Tips and hints

We have compiled a number of helpful tips in the appendix of this course (Section A.1), some of which will hopefully be helpful on your journey towards mastering the unix shell. For now, we recommend at the very least checking out the section on tab-completion and your command history. In fact, you can give it a try already. Just press the up arrow and see if you can recall your previous command! Next, try to type out ec, and press <tab>, to see auto-complete in action.