Special Shell Features

Ease of Use

Tab: Autocompletion

Before finishing typing a command or filename, pressing the Tab key will complete the name, saving you some typing. This autocomplete will only work if the characters typed up to that point are able to uniquely identify the word. If Tab autocomplete does not work at first, hit it twice to see a short list of possible matches.

Up/Down: Previous Commands

Pressing the Up key at anytime will begin cycling back through previously types commands. Pressing down in this list will move forward. The history command will produce a large list of previously entered commands.

Keyboard Shortcuts
  • Ctrl-a : goto beginning of line
  • Ctrl-e : goto end of line
  • Ctrl-u : clear line from beginning up until cursor position
  • Ctrl-k : clear line from cursor to end of line
  • Ctrl-c : kill currently running program
  • Ctrl-z : pause currently running program. Use <code>fg</code> to continue.

Environmental Considerations

Strings & Special Characters

Strings are any portion of text surrounding by either double quotes or single quotes. Double quoted strings appearing in a command will have environment variables replaced, whereas single quoted strings will not do such substitutions.

# echo "My home directory is $HOME"
# echo 'My home directory is $HOME'

Because some characters have special meaning in the shell, it can be important to use the escape character / to get rid of that special meaning.

# echo 'Who\'s having fun?'
# echo "Don't forget to escape your \$"

Environment Variables

The shell is it's own programming language. Part of the shell's operation is using environment variables to keep track of important information. The $PATH variable keeps a list of the directories to find executable programs. The whereis command will look through the $PATH list and output the first directory it finds a program name. You can even create your own variables!

# echo $PATH
# whereis ls
# whereis whereis
# MYVAR = "hello, world"
# echo $MYVAR

Globbing

The glob operator * was seen in the last section to select every file that started with the string "file". This procedure is called filename expansion. Often, the * character is also called the wildcard operator, since it can stand for any character or string sequence. Using overly broad wildcard statements can be quite dangerous if done wrong. For example: which files would the following command delete?

# rm *

Absolute vs. Relative Addressing

When executing commands that involve a filename, the default behavior is to look for files in the current directory. Commands can also use absolute addressing where the full file path is specified. Absolute references begin with a / (the root directory) and must contain every subfolder of a particular file. This even works with the executable program name itself. Any file reference that does not start with a / searches from the current directory.

# cd /bin
# ls
# cd /usr
# ls
# cd bin
# /bin/ls

Notice the last command invoked the ls program using absolute addressing. The shell will use the $PATH variable to search for program names if the program is not invoked with an absolute reference.

Last modified: Tuesday, 16 June 2020, 4:08 AM