Korn shell or POSIX shell commands

The Korn shell is an interactive command interpreter and command programming language. It conforms to the Portable Operating System Interface for Computer Environments (POSIX), an international standard for operating systems.

POSIX is not an operating system, but is a standard aimed at portability of applications, at the source level, across many systems. POSIX features are built on top of the Korn shell. The Korn shell (also known as the POSIX shell) offers many of the same features as the Bourne and C shells, such as I/O redirection capabilities, variable substitution, and file name substitution. It also includes several additional command and programming language features:

Note: There is a restricted version of Korn shell available, called rksh. For more details, refer to the rksh command.
Item Description
Arithmetic evaluation The Korn shell, or POSIX shell, can perform integer arithmetic using the built-in let command, using any base from 2 to 36.

In order to enable recognition of numbers starting with 0 (Octal) and 0x (Hexadecimal) in the Korn shell, run the following commands:

export XPG_SUS_ENV=ON
Exporting the XPG_SUS_ENV variable causes the commands that are run and the libraries that they use to be completely POSIX-compliant.
Note: Because the entire library system becomes POSIX-compliant, a given command's default expected behavior might change.
export OCTAL_CONST=ON
Exporting this variable causes the interpretation of constants declared in the Korn shell to be POSIX-compliant as far as the recognition of octal and hexadecimal constants is concerned.
Command history The Korn shell, or POSIX shell, stores a file that records all of the commands you enter. You can use a text editor to alter a command in this history file and then reissue the command.
Coprocess facility Enables you to run programs in the background and send and receive information to these background processes.
Editing The Korn shell, or POSIX shell, offers inline editing options that enable you to edit the command line. Editors similar to emacs, gmacs, and vi are available.

A Korn shell command is one of the following:

When you issue a command in the Korn shell or POSIX shell, the shell evaluates the command and does the following:

  • Makes all indicated substitutions.
  • Determines whether the command contains a slash (/). If it does, the shell runs the program named by the specified path name.

If the command does not contain a slash (/), the Korn shell or POSIX shell continues with the following actions:

  • Determines whether the command is a special built-in command. If it is, the shell runs the command within the current shell process.
  • Compares the command to user-defined functions. If the command matches a user-defined function, then the positional parameters are saved and then reset to the arguments of the function call. When the function completes or issues a return, the positional parameter list is restored, and any trap set on EXIT within the function is carried out. The value of a function is the value of the last command executed. A function is carried out in the current shell process.
  • If the command name matches the name of a regular built-in command, then that regular built-in command will be invoked.
  • Creates a process and attempts to carry out the command by using the exec command (if the command is neither a built-in command nor a user-defined function).

The Korn shell, or POSIX shell, searches each directory in a specified path for an executable file. The PATH shell variable defines the search path for the directory containing the command. Alternative directory names are separated with a colon (:). The default path is /usr/bin: (specifying the /usr/bin directory, and the current directory, in that order). The current directory is specified by two or more adjacent colons, or by a colon at the beginning or end of the path list.

If the file has execute permission but is not a directory or an a.out file, the shell assumes that it contains shell commands. The current shell process creates a subshell to read the file. All nonexported aliases, functions, and named parameters are removed from the file. If the shell command file has read permission, or if the setuid or setgid bits are set on the file, then the shell runs an agent that sets up the permissions and carries out the shell with the shell command file passed down as an open file. A parenthesized command is run in a subshell without removing nonexported quantities.