Hitachi

Job Management Partner 1 Version 10 Job Management Partner 1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide


which command (obtains the paths of external commands)

Organization of this page

Format

which[-a]command-name ...

Description

This command obtains the paths of external commands to be executed from the command search path set in the PATH environment variable. The command outputs the obtained command paths to the standard output.

Arguments

-a

Specifies that all executable command paths are to be obtained from the command search path set in the PATH environment variable.

When the -a option is omitted, the command output only the first command path obtained.

command-name

Specifies the name of an external command whose command path is to be obtained. You can specify multiple command names.

If the command path of a specified external command is not found, the which command outputs a message to that effect to the standard error output.

Command path search rules

The command searches for the command paths of external commands according to the rules described below.

In Windows:
Paths subject to external command search

The command searches the command search path set in the PATH environment variable for the external commands. If multiple command paths are set in the PATH environment variable, the command searches the command paths in order from the beginning. If the user executing the which command does not have permissions to read the external command storage directory, that directory is not subject to command path search.

External commands whose command paths are to be output

If the user executing the which command has permissions to read the external command storage directory, the which command outputs the corresponding command paths. The which command does not check whether the user has permissions to execute the external command.

The which command can output the paths of external commands if they are executable files with the extension .com, .exe, .cmd, or .bat.

If a specified external command contains no extension, the which command adds the extensions defined in the PATHEXT environment variable in the order defined and then searches the external commands. The supported extensions are .com, .exe, .cmd, and .bat. For details, see 5.1.11 Specifying external commands.

In UNIX:
Paths subject to external command search

The command searches the command search path set in the PATH environment variable for the external commands. If multiple command paths are set in the PATH environment variable, the command searches the command paths in order from the beginning. If the user executing the which command does not have permissions to search the external command storage directory (including all directories in the path), that directory is not subject to command path search.

External commands whose command paths are to be output

If the user executing the which command has permissions to execute a specified external command, the which command determines that that external command is executable and outputs its command path. If the user does not have permissions to execute a specified external command, that external command's path is not output.

When the command names specified in the argument contain paths

In Windows:

If the user executing the which command has permissions to read the external command storage directory, the which command outputs the corresponding command paths. The which command does not check whether the user has permissions to execute the external command.

If the user executing the which command does not have permissions to read the external command storage directory, the which command outputs a message indicating that the external command's command path was not found.

The which command can output the paths of external commands if they are executable files with extension .com, .exe, .cmd, or .bat.

If the specified external commands contain no extension, the which command adds to the external command names the extensions defined in the PATHEXT environment variable in the order defined. The supported extensions are .com, .exe, .cmd, and .bat.

In UNIX:

If the user executing the which command has permissions to search the external command storage directory (including all directories in the path) and the external command execution permissions, the which command outputs the command names specified in the argument. If the user executing the which command does not have these permissions, the which command outputs a message indicating that the external command's command path was not found.

Return code

Return code

Meaning

0

Normal termination

1

Error termination

The command path of the external command was not found; or, if multiple external commands were searched, at least one external command's command path was not found.

2

Error termination

  • An invalid option was specified.

  • The PATH environment variable is undefined.

  • In Windows, the PATHEXT environment variable is undefined.

Notes

Usage examples