Bash Command Precedence Explained

Shell Scripting

Unlike some other operating systems, Linux does not, by default, check the current directory for an executable before searching the path. It immediately begins searching the path, and executables in the current directory are run only if they are in the PATH variable or you give their absolute (such as /home/ or relative (for example, ./ address.





1. Aliases. Names set by the alias command that represent a particular command and a set of options. Type alias to see what aliases are set. Often, aliases enable you to define a short name for a long, complicated command.

2. Shell reserved word. Words reserved by the shell for special use. Many of these are words that you would use in programming-type functions, such as do, while, case, and else.

3. Function. A set of commands that are executed together within the current shell.

4. Built-in command. A command built into the shell. As a result, there is no representation of the command in the fi le system. Some of the most common commands you will use are shell built-in commands, such as cd (to change directories), echo (to output text to the screen), exit (to exit from a shell), fg (to bring a command running in the background to the foreground), history (to see a list of commands that were previously run), pwd (to list the present working directory), set (to set shell options), and type (to show the location of a command).

5. File system command. This command is stored in and executed from the computer’s file system. (These are the commands that are indicated by the value of the PATH variable.)


(If you are using a shell other than bash, use which command instead.) For example, to fi nd out where the bash shell command is located, type the following:

$ type bash

bash is /bin/bash


If a command is not in your PATH variable, you can use the locate command to try to find it. Using locate, you can search any part of the system that is accessible to you (some files are only accessible to the root user).

$ locate lsof


Leave a Reply