Customizing the search path for commands: The PATH variable

Command interpreters usually have to search for a file that contains the command you want to run. When you are using the shell, you tell the shell where to search for a command. Essentially, the shell uses a list of directories in which commands may be found. This list is specified in your PATH variable in your .profile file. The list could be called your search path, because it tells the shell where you want to search.

You can set up a search path with a command of the form:
PATH='dir:dir:...'
For example, you might enter:
PATH='/bin:/usr/bin:/usr/etc:/usr/macneil/bin:/usr/games:/usr'
The shell then searches the directories in the following order, when looking for commands or shell scripts:
  1. /bin
  2. /usr/bin
  3. /usr/etc
  4. /usr/macneil/bin
  5. /usr/games
  6. /usr

As soon as the shell finds a file with an appropriate name, it runs that file.

Because the shell runs a command as soon as it finds a file with an appropriate name, pay close attention to the order in which you list directory names in your search path. For example, the previous search path specifies the /bin directory (where z/OS® shell commands are stored) before the /etc directory.

If you set up your PATH incorrectly, you could get the wrong command. Always search the shell commands directory first: /bin. Some z/OS shell commands run other shell commands and utilities by name; they expect to get the z/OS UNIX version of that command and might not work correctly if a program that has the same name is found first in another directory.

Tip: To ensure that the z/OS shell properly identifies a shell built-in command, specify the shell commands directory /bin exactly as /bin (not as /bin/ or any other variation) in addition to making the shell commands directory /bin part of your PATH. Some commands located in /bin are implemented as shell built-in commands in order to improve performance of shell scripts. The directories specified in PATH influence how the shell locates commands, including the built-in commands, which also influence how the shell handles tracked aliases. See Using alias tracking for more information about tracked aliases.