|
|
HP-UX Reference Volume 1 of 5 > ssh-bourne(1) |
|
NAMEsh, rsh — Bourne shell, the standard/restricted command programming language DESCRIPTIONsh is a command programming language that executes commands read from a terminal or a file. rsh is a restricted version of the standard command interpreter sh; it is used to set up login names and execution environments whose capabilities are more controlled than those of the standard shell. See ``Invocation'' and ``Special Commands'' sections later in this entry for details about command line options and arguments, particularly the set command. DefinitionsA blank is a tab or a space character. A name is a sequence of letters, digits, or underscores beginning with a letter or underscore. A parameter is a name, a digit, or any of the characters *, @, #, ?, -, $, and !. CommandsA simple-command is a sequence of non-blank words separated by blanks. The first word specifies the name of the command to be executed. Except as specified below, the remaining words are passed as arguments to the invoked command. The command name is passed as argument 0 (see exec(2)). The value of a simple-command is its exit status if it terminates normally, or (octal) 200+status if it terminates abnormally (see signal(5) for a list of status values). A pipeline is a sequence of one or more commands separated by | (or, for historical compatibility, by ^). The standard output of each command except the last is connected by a pipe(2) to the standard input of the next command. Each command is run as a separate process and the shell waits for the last command to terminate. The exit status of a pipeline is the exit status of the last command. A list is a sequence of one or more pipelines separated by ;, &, &&, or ||, and optionally terminated by ; or &. Of these four symbols, ; and & have equal precedence, which is lower than that of && and ||. The symbols && and || also have equal precedence. A semicolon (;) causes sequential execution of the preceding pipeline; an ampersand (&) causes asynchronous execution of the preceding pipeline (i.e., the shell does not wait for that pipeline to finish). The symbol && (||) causes the list following it to be executed only if the preceding pipeline returns a zero (non-zero) exit status. An arbitrary number of new-line characters instead of semicolons can appear in a list to delimit commands. A command is either a simple-command or one of the following. Unless otherwise stated, the value returned by a command is that of the last simple-command executed in the command.
The following words are recognized only as the first word of a command, and when not quoted: if then else elif fi case esac for while until do done { } CommentsA word beginning with # causes that word and all the following characters up to a new-line character to be ignored. Command SubstitutionThe standard output from a command enclosed in a pair of grave accents (``) can be used as part or all of a word; trailing new-lines are removed. Parameter SubstitutionThe $ character is used to introduce substitutable parameters. There are two types of parameters, positional and keyword. If parameter is a digit, it is a positional parameter. Positional parameters can be assigned values by set. Keyword parameters (also known as variables) can be assigned values by writing: name=value[name=value]... Pattern-matching is not performed on value. Having a function and a variable with the same name is not allowed.
In the above, word is not evaluated unless it is to be used as the substituted string. Thus, in the following example, pwd is executed only if d is not set or is null: echo ${d:-`pwd`} If the colon (:) is omitted from the above expressions, the shell only checks whether parameter is set or not. The following parameters are automatically set by the shell:
The following parameters are used by the shell:
The shell gives default values to PATH, PS1, PS2, MAILCHECK, and IFS. HOME and MAIL are set by login(1). Blank InterpretationAfter parameter and command substitution, the results of substitution are scanned for internal field separator characters (those found in IFS) and split into distinct arguments where such characters are found. Explicit null arguments ("" or \'\') are retained. Implicit null arguments (those resulting from parameters that have no values) are removed. File Name GenerationFollowing substitution, each command word is processed as a pattern for file name expansion. The form of the patterns is the Pattern Matching Notation defined by regexp(5). QuotingThe following characters have a special meaning to the shell and cause termination of a word unless quoted: ;, &, (, ), |, ^, <, >, new-line, space, tab, # (comment) A character can be quoted (i.e., made to stand for itself) by preceding it with a \. The pair \new-line is ignored. All characters enclosed between a pair of single quote marks (\'\'), except a single quote, are quoted. Inside double quote marks (""), parameter and command substitution occurs and \ quotes the characters \, `, ", and $. "$*" is equivalent to "$1 $2 ...", whereas "$@" is equivalent to "$1""$2" .... PromptingWhen used interactively, the shell prompts with the value of PS1 before reading a command. If at any time a new-line is typed and further input is needed to complete a command, the secondary prompt (i.e., the value of PS2) is issued. Input/OutputBefore a command is executed, its input and output can be redirected using a special notation interpreted by the shell. The following can appear anywhere in a simple-command or can precede or follow a command and are not passed on to the invoked command; substitution occurs before word or digit is used:
If any of the above is preceded by a digit in the range 0 through 9, the file descriptor that becomes associated with the file is that specified by the digit (rather than the default 0 or 1). For example: ... 2>&1 associates file descriptor 2 with the file currently associated with file descriptor 1. Note that this type of I/O redirection is necessary when synchronously collecting standard output and standard error output in the same file. Redirecting standard output and standard error separately causes asynchronous collection of data at the destination (information written to standard output can be subsequently over-written by information written to standard error and vice-versa). The order in which redirections are specified is significant. The shell evaluates redirections left-to-right. For example: ... 1>xxx 2>&1 first associates file descriptor 1 with file xxx. It associates file descriptor 2 with the file associated with file descriptor 1 (i.e. xxx). If the order of redirections is reversed, file descriptor 2 is associated with the terminal (assuming file descriptor 1 was originally) and file descriptor 1 is associated with file xxx. If a command is followed by &, the default standard input for the command is the empty file /dev/null. Otherwise, the environment for executing a command contains the file descriptors of the invoking shell as modified by input/output specifications. Redirection of output is not allowed in the restricted shell. EnvironmentThe environment (see environ(5)) is a list of name-value pairs that is passed to an executed program in the same way as a normal argument list. The shell interacts with the environment in several ways. On invocation, the shell scans the environment and creates a parameter for each name found, giving it the corresponding value. Executed commands inherit the same environment. If the user modifies the value of any of these parameters or creates new parameters, none of these affects the environment unless the export command is used to bind the shell's parameter to the environment (see also set -a). To remove a parameter from the environment, use the unset command. The environment seen by any executed command is thus composed of any unmodified name-value pairs originally inherited by the shell, minus any pairs removed by unset, plus any modifications or additions, all of which must be noted in export commands. The environment for any simple-command can be augmented by prefixing it with one or more assignments to parameters. Thus: TERM=450 cmd and (export TERM; TERM=450; cmd) are equivalent (as far as the execution of cmd is concerned). If the -k option is set, all keyword arguments are placed in the environment, even if they occur after the command name. The following first prints a=b c and then c: echo a=b c set -k echo a=b c SignalsThe INTERRUPT and QUIT signals for an invoked command are ignored if the command is followed by & and the command does not override the SIGINT and SIGQUIT signal settings it inherited from /usr/old/bin/sh; otherwise signals have the values inherited by the shell from its parent, with the exception of signal 11 (but see also the trap command below). If a SIGWINCH signal is received, sh determines the new size of the display area and resets the values of the LINES and COLUMNS variables appropriately. Note that the value of either variable is modified only if that variable exists at the time SIGWINCH is received. sh does not create these variables. Any traps set on SIGWINCH are executed immediately after LINES and COLUMNS are reset. ExecutionEach time a command is executed, the above substitutions are carried out. If the command name matches one of the Special Commands listed below, it is executed in the shell process. If the command name does not match a Special Command, but matches the name of a defined function, the function is executed in the shell process (note how this differs from the execution of shell procedures). The positional parameters $1, $2, .... are set to the arguments of the function. If the command name matches neither a Special Command nor the name of a defined function, a new process is created and an attempt is made to execute the command via exec(2). The shell parameter PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The default path is :/usr/bin (specifying the current directory and /usr/bin, in that order). Note that the current directory is specified by a null path name, which can appear immediately after the equal sign or between the colon delimiters anywhere else in the path list. If the command name contains a / the search path is not used (such commands are not executed by the restricted shell). Otherwise, each directory in the path is searched for an executable file. If the file has execute permissions but is not a directory or an executable object code file, it is assumed to be a script file which is a file of data for an interpreter. If the first two characters of the script file are #!, exec (see exec(2)) expects an interpreter path name to follow. exec then attempts to execute the specified interpreter as a separate process to read the entire script file. If a call to exec fails, /usr/old/bin/sh is spawned to interpret the script file. A parenthesized command is also executed in a sub-shell. The location in the search path where a command was found is remembered by the shell (to help avoid unnecessary execs later). If the command was found in a relative directory, its location must be re-determined whenever the current directory changes. The shell forgets all remembered locations whenever the PATH variable is changed or the hash -r command is executed (see below). Special CommandsThe following commands are executed in the shell process. Input/output redirection is permitted for these commands. File descriptor 1 is the default output location.
InvocationOptions can be specified in a single argument or in multiple arguments, but in all cases each option argument must begin with -. (All options except c, s, i, and r can also be prefaced with a +, which turns off the associated option or options, but this is redundant when invoking a new shell because all options are turned off by default). If the first character of argument zero is -, commands are initially read from /etc/profile, then from $HOME/.profile, if the files exist. Thereafter, commands are read as described below. The options below are interpreted by the shell at invocation (thus they cannot be used with the set command). Unless the -c or -s option is specified, the first non-option argument is assumed to be the name of a file containing commands, and the remaining arguments are passed as positional parameters to that command file.
The remaining options and arguments are described under the set command above. rsh Onlyrsh is used to set up login names and execution environments whose capabilities are more controlled than those of the standard shell. The actions of rsh are identical to those of sh, except that the following are disallowed:
The restrictions above are enforced after .profile is interpreted. When a command to be executed is found to be a shell procedure, rsh invokes sh to execute it. Thus, it is possible to provide to the end-user shell procedures that have access to the full power of the standard shell, while imposing a limited menu of commands; this scheme assumes that the end-user does not have write and execute permissions in the same directory. The net effect of these rules is that the writer of the .profile has complete control over user actions, by performing guaranteed setup actions and leaving the user in an appropriate directory (probably not the login directory). The system administrator often sets up a directory of commands (such as /usr/rbin) that can be safely invoked by rsh. Commands such as vi, sh, ksh, csh, and such that can break rsh restrictions should not be included in that directory. Some systems also provide a restricted editor red. EXTERNAL INFLUENCESEnvironment VariablesLC_COLLATE determines the collating sequence used in evaluating pattern matching notation for file name generation. LC_CTYPE determines the interpretation of text as single and/or multi-byte characters, the classification of characters as letters, and the characters matched by character class expressions in pattern matching notation. LANG determines the language in which messages are displayed. If LC_COLLATE or LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, sh behaves as if all internationalization variables are set to "C". See environ(5). RETURN VALUEThe error codes returned by the shell are:
If the shell is non-interactive, it terminates and passes one of the above as its exit status. If it is interactive, it does not terminate, but $? is set to one of the above values. Whenever a child process of the shell dies due to a signal, the shell returns an exit status of 80 hexadecimal plus the number of the signal. WARNINGSIf a command is executed and a command having the same name is installed in a directory in the search path before the directory where the original command was found, the shell continues to exec the original command. Use the hash command to correct this situation. When the shell encounters >>, it does not open the file in append mode. Instead, it opens the file for writing and seeks to the end. If you move the current directory or one above it, pwd cannot give the correct response. Use the cd command with a full path name to correct this situation. The command readonly (without arguments) produces the same output as the command export. Failure (non-zero exit status) of a special command preceding a || symbol prevents the list following || from executing. In an international environment, character ordering is determined by the setting of LC_COLLATE, rather than by the binary ordering of character values in the machine collating sequence. This brings with it certain attendant dangers, particularly when using range expressions in file-name-generation patterns. For example, the command, rm [a-z]* might be expected to match all file names beginning with a lowercase alphabetic character. However, if dictionary ordering is specified by LC_COLLATE, it also matches file names beginning with an uppercase character (as well as those beginning with accented letters). Conversely, it fails to match letters collated after z in languages such as Norwegian. The correct (and safe) way to match specific character classes in an international environment is to use a pattern of the form: rm [[:lower:]]* This uses LC_CTYPE to determine character classes and works predictably for all supported languages and codesets. For shell scripts produced on non-internationalized systems (or without consideration for the above dangers), it is recommended that they be executed in a non-NLS environment. This requires that LANG, LC_COLLATE, etc., be set to "C" or not set at all. sh implements command substitution by creating a pipe between itself and the command. If the root file system is full, the substituted command cannot write to the pipe. As a result, the shell receives no input from the command, and the result of the substitution is null. In particular, using command substitution for variable assignment under such circumstances results in the variable being silently assigned a NULL value. The signal SIGSEGV should not be blocked when executing sh. sh reserves file descriptor 59 for internal use. Reducing the number of available file descriptors below 60 causes sh to fail. Each time a function is executed in a shell script, any arguments given to the function overwrite the values of the positional parameters for the entire script. If the values of the positional parameters must be preserved, they must be explicitly saved before each function call. SEE ALSOcd(1), echo(1), env(1), login(1), newgrp(1), pwd(1), test(1), umask(1), acctcms(1M), acctcom(1M), dup(2), exec(2), fork(2), pipe(2), ulimit(2), umask(2), wait(2), a.out(4), profile(4), environ(5), lang(5), regexp(5), signal(5). Bourne Shell tutorial in Shells Users Guide. STANDARDS CONFORMANCE.: SVID2, SVID3, XPG2, XPG3 :: SVID2, SVID3, XPG2, XPG3 break: SVID2, SVID3, XPG2, XPG3 case: SVID2, SVID3, XPG2, XPG3 continue: SVID2, SVID3, XPG2, XPG3 eval: SVID2, SVID3, XPG2, XPG3 exec: SVID2, SVID3, XPG2, XPG3 exit: SVID2, SVID3, XPG2, XPG3 export: SVID2, SVID3, XPG2, XPG3 for: SVID2, SVID3, XPG2, XPG3 if: SVID2, SVID3, XPG2, XPG3 read: SVID2, SVID3, XPG2, XPG3 return: SVID2, SVID3, XPG2, XPG3 rsh: SVID2, SVID3 set: SVID2, SVID3, XPG2, XPG3 sh: SVID2, SVID3, XPG2, XPG3 shift: SVID2, SVID3, XPG2, XPG3 time: SVID2, SVID3, XPG2, XPG3 trap: SVID2, SVID3, XPG2, XPG3 unset: SVID2, SVID3, XPG2, XPG3 until: SVID2, SVID3, XPG2, XPG3 |
|