Command Order of Precedence
The common misconception is that the shell always searches the PATH variable to find a command. The truth is that the shell may never get to the PATH variable before it has a name match. Before confusing the issue, let’s look at a simple example. If there is an alias that reads which=’whence -a’, and you enter which pwd, the which command is never executed. The shell first finds the alias, and then subsitutes the alias for the command, and starts the search all over. From this, we know that an alias has precedence over the PATH variable. So what is the order of precedence for finding the command?
