Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

sh - shell, the standard command language interpreter

&pagelevel(4)&pagelevel

In the login shell, commands are read sequentially from the file /etc/profile and then, if the files exist, either from the .profile of the current directory or from $HOME/.profile. Following this, commands are also read from the file whose name is defined by the value of the shell variable ENV following parameter substitution.


Syntax


sh[ option...][ file][ argument]...

No option specified

A subshell with the option -s is called. The shell process which was already current becomes the parent of the new shell. Depending on which terminal you are using, you can terminate the subshell either with CTRL+D or @@d or with the exit command.

option

When called, sh interprets the options below as well as the options which are described under the POSIX shell built-in set command:

-c command_string

The commands are read from command_string.

-s

If the option -s is specified or if file and argument are specified then the POSIX shell reads the commands from the standard input and writes output to the standard output. Only diagnostic messages are written to the standard error output.

-i

If the option -i is specified or if the standard input and output are connected to a video display terminal then an interactive POSIX shell is called. In this case, TERM is ignored to prevent kill 0 from terminating an interactive shell and INTR is intercepted and ignored so that wait can be interrupted. In all cases, the POSIX shell ignores QUIT.

-r

The -r option calls a restricted POSIX shell, in which the following restrictions apply:

  • The shell built-in command cd is rejected, which means you cannot leave your current working directory.

  • You cannot change the value of the PATH variable.

  • Commands are rejected if the command file name contains a slash /. You can only execute commands which are in your current working directory or in directories on the paths assigned to the PATH shell variable.

  • Commands are rejected if the command line includes > or >>. In other words, you cannot use > or >> to redirect command output to a file.

To exit a restricted subshell you use CTRL+D or @@d or the exit command, depending on terminal type.

file

If option -s has not been specified but file has been, the shell procedure file is searched for at the location specified in the search path. The read permission must be set for the procedure. If the s-bit is set for the owner or group, then it is ignored. Commands are read as described below.

argument

You may enter commands as arguments. The command name is passed as argument zero. The commands are described below.

If the POSIX shell is called by means of the system call exec and if the first character of the zero argument is a hyphen , then the shell is treated as a login shell.

Exit status

The POSIX shell normally returns the exit status of the last command executed (see exit).

Errors detected by the POSIX shell (syntax errors for example) result in an exit status which is not equal to zero. If you are not using the POSIX shell interactively, processing of the script file is interrupted. If the POSIX shell detects runtime errors it reports these by outputting the command name and error conditions. If the line number of the line which contains the incorrect command is greater than one, the line number is output in square brackets [...] after the command or function name.

File

/etc/profile
/etc/suid_profile
$HOME/.profile
/tmp/sh*
/dev/null

Variable

The following variables affect sh:

FCEDIT, HISTFILE, HISTSIZE, HOME, IFS, MAIL, MAIL, MAILCHECK, MAILPATH and PATH

(description see the section “POSIX shell variables and parameter substitution”).

Locale

The following environment variables affect the execution of sh:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_COLLATE

Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within pattern matching.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), which characters are defined as letters, and the behavior of character classes within pattern matching.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

See also

cat, cd, chmod, cut, echo, env, paste, stty, test, umask, vi

dup(), exec(), fork(), getrlimit(), ioctl(), lseek(), pipe(), signal(), umask(), ulimit(), wait(), rand() [4]