2014-10-14 How does the shell search for some command to be executed? Where does it search if I enter: foo/bar a b Would it search for a directory `foo', containing a file `bar', inside of each of the directories in $PATH? To find answers to such questions, it's worth to have a look at POSIX. [0] Command Search and Execution If a simple command results in a command name and an optional list of arguments, the following actions shall be performed: 1. If the command name does not contain any characters, the first successful step in the following sequence shall occur: a) If the command name matches the name of a special built-in utility, that special built-in utility shall be invoked. b) If the command name matches the name of a function known to this shell, the function shall be invoked as described in Function Definition Command. [...] c) If the command name matches the name of a utility listed in the following table, that utility shall be invoked. [...] alias, bg, cd, [...] d) Otherwise, the command shall be searched for using the PATH environment variable as described in XBD Environment Variables: [...] 2. If the command name contains at least one , the shell shall execute the utility in a separate utility environment with actions equivalent to calling the execl() function defined in the System Interfaces volume of POSIX.1-2008 with the path and arg0 arguments set to the command name, and the remaining execl() arguments set to the command arguments (if any) and the null terminator. If the execl() function fails due to an error equivalent to the [ENOEXEC] error, the shell shall execute a command equivalent to having a shell invoked with the command name as its first operand, with any remaining arguments passed to the new shell. If the executable file is not a text file, the shell may bypass this command execution. In this case, it shall write an error message and shall return an exit status of 126. [...] [1] Seems as if there someone should start to announce POSIX snippets of the week. ;-) [0] http://pubs.opengroup.org/onlinepubs/9699919799/ [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01 http://marmaro.de/lue/ markus schnalke