An important part of the tasks of the shell is to search for commands. Bash does this as follows:
Check whether the command contains slashes. If not, first check with the function list to see if it contains a command by the name we are looking for.
If command is not a function, check for it in the built-in list.
If command is neither a function nor a built-in, look for it analyzing the directories listed in PATH . Bash uses a hash table (data storage area in memory) to remember the full path names of executables so extensive PATH searches can be avoided.
If the search is unsuccessful, bash prints an error message and returns an exit status of 127.
If the search was successful or if the command contains slashes, the shell executes the command in a separate execution environment.
If execution fails because the file is not executable and not a directory, it is assumed to be a shell script.
If the command was not begun asynchronously, the shell waits for the command to complete and collects its exit status.
1.4.1.8. Shell scripts
When a file containing shell commands is used as the first non-option argument when invoking Bash (without -c or -s , this will create a non-interactive shell. This shell first searches for the script file in the current directory, then looks in PATH if the file cannot be found there.
Prev
Home
Next
Executing commands
Up
Developing good scripts

