Simple Commands

The fundamental building block of the shell command language is called a simple command. A simple consists of variable assignments, I/O redirections, and a list of command words which are processed to form a command name and its arguments. The most basic and intuitive example of a simple command is one which is simply a command name and its arguments, without redirection or assignment. For example, the following simple command invokes the echo utility to print its arguments–“Hello” and “World!”–to standard output:

$ echo Hello World!
Hello World!

Note

Notice the “$” prompt string preceding the echo command name. The string, “$”, is the default prompt for a regular user in the POSIX shell, which is printed before the shell waits for a line of input. Records or examples of interactive shell sessions conventionally include a leading “$” on each command line in order to easily differentiate commands from output. You may also come across “#” used as a prompt string; this is the default prompt for a root user, and indicates that the command is executed with elevated privileges:

$ whoami
bennyb
# whoami
root

It is important to recognize when you are looking at a record or example of an interactive session compared to an example of a shell script, since ‘$’ and ‘#’ are also valid characters that might appear at the start of a line in a shell script. Usually it’s not too hard to spot one from the other once you get used to seeing both, especially if syntax highlighting is involved. The same text above, taken verbatim as a shell script,

$ whoami
bennyb
# whoami
root

Would run the command named $ with an argument “whoami”; then run the command named bennyb; then skip a comment (# whoami); and finally run the command root.

Since $, bennyb, and root probably aren’t the names of any utilities on a system, the result of running each line as a raw command would likely be:

sh: $: command not found
sh: bennyb: command not found
sh: root: command not found

As you can see, it’s important to discern what you are looking at! Never blindly copy and paste commands into a terminal or script.