SH
Section: Misc. Reference Manual Pages (1L)
Updated: MS-DOS - OS/2 Version 2.3
Index
Return to Main Contents
NAME
sh, rsh - shell, the standard/restricted command programming language
SYNOPSIS
sh [ -acefhiknmrstuvx0R ] [ args ]
rsh [ -acefhiknmrstuvx0R ] [ args ]
DESCRIPTION
sh 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 below for the meaning of arguments to the shell.
Definitions
A blank is a tab or a space. 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 !.
Commands
A 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(2) 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 but the last is connected by a pipe(2)
to the standard input of the next command. Each command is run as a separate
process; 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 ;,
& (OS/2 only), &&, or ||, and optionally
terminated by ; or & (OS/2 only). Of these four symbols,
; and & have equal precedence, which is lower precedence 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
command to finish. This option is only available under OS/2 and is
restricted to single commands and not pipelines because of the differences in
the UNIX and OS/2 process models). 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-lines may appear in a list, instead of semicolons, 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.
- for name [ in word ... ] do list done
-
Each time a for command is executed, name is set to the next
word taken from the in word list. If in word ...
is omitted, then the for command executes the do
list once for each positional parameter that is set (see Parameter
Substitution below). Execution ends when there are no more words in the
list.
- select name [ in word ... ] do list done
-
A select command prints on standard error (file descriptor 2), the set
of words, each preceded by a number. If in word ... is omitted,
then the positional parameters are used instead (see Parameter
Substitution below). The PS3 prompt is printed and a line is read
from the standard input. If this line consists of the number of one of the
listed words, then the value of the parameter name is set to the
word corresponding to this number. If this line is empty the selection
list is printed again. Otherwise the value of the parameter name is set
to null. The contents of the line read from standard input is saved in the
parameter REPLY. The list is executed for each selection until a break
or end-of-file is encountered.
- case word in [ pattern [ | pattern ] ... ) list ;; ] ... esac
-
A case command executes the list associated with the first
pattern that matches word. The form of the patterns is the same
as that used for file-name generation (see File Name Generation) except
that a slash, a leading dot, or a dot immediately following a slash need not
be matched explicitly, and the match is case sensitive.
- if list then list [ elif list then list ] ... [ else list ] fi
-
The list following if is executed and, if it returns a zero exit
status, the list following the first then is executed. Otherwise,
the list following elif is executed and, if its value is zero, the
list following the next then is executed. Failing that, the
else list is executed. If no else list or then list
is executed, then the if command returns a zero exit status.
- while list do list done
-
A while command repeatedly executes the while list and, if
the exit status of the last command in the list is zero, executes the
do list; otherwise the loop terminates. If no commands in the
do list are executed, then the while command returns a zero
exit status; until may be used in place of while to negate the
loop termination test.
- (list)
-
Execute list in a sub-shell. The shell creates a new environment in
which to execute the list, but does not fork a sub-shell as a Unix
system would. The original environment is restored on completion.
- { list; }
-
list is simply executed.
- [[ expression ]]
-
Evaluates expression and returns a zero exit status when expression is true.
See Conditional Expressions below, for a description of expression.
Note that [[ and ]] are keywords and require
blanks between them and expression.
- function name { list; }
-
- name () { list; }
-
Define a function which is referenced by name. The body of the function
is the list of commands between { and }. Execution of
functions is described below (see Execution).
The following words are only recognised as the first word of a command and
when not quoted:
if then else elif fi case esac for while until do done { } [[ ]]
Comments
A word beginning with # causes that word and all the following
characters up to a new-line to be ignored.
Aliasing
The first word of each command is replaced by the text of an alias if an
alias for this word has been defined. The alias name must a valid identifier.
The replacement string can contain any valid Shell script including the
meta-characters listed above. The first word of each command of the
replaced text will not be tested for additional aliases. If the last
character of the alias value is a blank then the word following the alias
will also be checked for alias substitution. Aliases can be used to redefine
special built-in commands but cannot be used to redefine the keywords listed
above. Aliases can be created and listed with the alias command and
can be removed with the unalias command.
Aliasing is performed when scripts are read, not while they are executed.
Therefore, for an alias to take effect the alias command has to be executed
before the command which references the alias is read.
Aliases are frequently used as a short hand for full path names. An
option to the aliasing facility allows the value of the alias to be
automatically set to the full pathname of the corresponding command. These
aliases are called tracked aliases. The value of a tracked alias is
defined the first time the corresponding command is looked up and becomes
undefined each time the PATH variable is reset. These aliases remain
tracked so that the next subsequent reference will redefine the value.
Conditional Expressions
A conditional expression is used with the [[ compound command
to test attributes of files and to compare strings. Word splitting and file
name generation are not performed on the words between [[ and
]]. Each expression can be constructed from one or more of the
following unary or binary expressions:
-
- -a file
-
True if file exists.
- -b file
-
True if file exists and is a block special file.
- -c file
-
True if file exists and is a character special file.
- -d file
-
True if file exists and is a directory.
- -f file
-
True if file exists and is a regular file.
- -g file
-
True if file exists and has its setgid bit set.
- -h file
-
True if file exists and is a symbolic link.
- -k file
-
True if file exists and has its sticky bit set. Under MS-DOS and
OS/2, the sticky bit is equivalent to the ARCHIVED attribute.
- -n string
-
True if the length of string is non-zero.
- -o option
-
True if the option named is on.
- -p file
-
True if file exists and is a FIFO special file or a pipe.
- -r file
-
True if file exists and is readable.
- -s file
-
True if file exists and has a size greater than zero.
- -t [ fildes ]
-
True if the open file whose file descriptor number is fildes (1 by
default) is associated with a terminal device.
- -u file
-
True if file exists and has its setuid bit set.
- -w file
-
True if file exists and is writable.
- -x file
-
True if file exists and is executable. If file exists and is a
directory, then the current process has permission to search in the directory.
- -z string
-
True if the length of string is zero.
- -L file
-
True if file exists and is a symbolic link.
- -O file
-
True if file exists and is owned by the effective user id of this process.
Under MS-DOS and OS/2, the UID bit is equivalent to the HIDDEN
attribute.
- -G file
-
True if file exists and is owned by the effective user group of this
process. Under MS-DOS and OS/2, the GID bit is equivalent to the
SYSTEM attribute.
- -S file
-
True if file exists and is a socket.
- file1 -nt file2
-
True if file1 is newer than file2.
True if file1 exists and is newer than file2.
- file1 -ot file2
-
True if file1 exists and is older than file2.
- file1 -ef file2
-
True if file1 and file2 and refer to the same file. Under
MS-DOS and OS/2, inode information is not available, and the
shell compares the absolute filenames.
- s1 = s2
-
True if strings s1 and s2 are identical.
- s1 != s2
-
True if strings s1 and s2 are not identical.
- s1 < s2
-
True if string s1 comes before s2 are based on the ASCII value of
their characters.
- s1 > s2
-
True if string s1 comes after s2 are based on the ASCII value of
their characters.
- n1 -eq n2
-
True if n1 is equal to n2.
- n1 -ne n2
-
True if n1 is not equal to n2.
- n1 -lt n2
-
True if n1 is less than to n2.
- n1 -gt n2
-
True if n1 is greater than to n2.
- n1 -le n2
-
True if n1 is less than or equal to n2.
- n1 -ge n2
-
True if n1 is greater than or equal to n2.
Not all of the above have meaning under MS-DOS or OS/2. In such
cases, the appropriate value is set (false, except for -O and
-G).
A compound expression can be constructed from these primitives by using any of
the following, listed in decreasing order of precedence.
-
- ( expr )
-
True, if expr is true. Used to group expressions.
- ! expr
-
True, if expr is false.
- expr1 && expr2
-
True, if expr1 and expr2 are both true.
- expr1 || expr2
-
True, if expr1 or expr2 is true.
Tilde Substitution
Each word is checked to see if it begins with an unquoted ~. If it is,
the ~ is replaced by the value of the HOME parameter. A ~
followed by a + or - is replaced by the value of the parameter
PWD and OLDPWD respectively.
Command Substitution
The standard output from a command enclosed in parenthesis preceded by a
dollar sign ($()), or in a pair of grave accents (``) may
be used as part or all of a word; trailing new-lines are removed. The command
substitution $(cat file) can be replaced by the equivalent but
faster $(<file).
Parameter Substitution
The 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 may be
assigned values by set. Keyword parameters (also known as variables)
may be assigned values by writing:
-
name = value [ name = value ] ...
Pattern-matching is not performed on value. There cannot be a function
and a variable with the same name.
Alternatively, named parameters can be assigned values and attributes by using
the typeset special command.
- ${parameter}
-
The value, if any, of the parameter is substituted. The braces are
required only when parameter is followed by a letter, digit, or
underscore that is not to be interpreted as part of its name. If
parameter is * or @, all the positional parameters, starting
with $1, are substituted (separated by spaces). Parameter $0 is
set from argument zero when the shell is invoked.
- ${#parameter}
-
If parameter is * or @, the number of positional parameters
is substituted. Otherwise, the length of the value of the parameter is
substituted.
- ${parameter:-word}
-
If parameter is set and is non-null, substitute its value; otherwise
substitute word.
- ${parameter:=word}
-
If parameter is not set or is null set it to word; the value of
the parameter is substituted. Positional parameters may not be assigned to
in this way.
- ${parameter:?word}
-
If parameter is set and is non-null, substitute its value; otherwise,
print word and exit from the shell. If word is omitted, the
message ``parameter null or not set´´ is printed.
- ${parameter:+word}
-
If parameter is set and is non-null, substitute word; otherwise
substitute nothing.
-
-
${parameter#pattern}
- ${parameter##pattern}
-
If the Shell pattern matches the beginning of the value of
parameter, then the value of this substitution is the value of the
parameter with the matched portion deleted; otherwise the value of
this parameter is substituted. In the first form the smallest matching
pattern is deleted and in the latter form the largest matching
pattern is deleted.
-
-
${parameter%pattern}
- ${parameter%%pattern}
-
If the Shell pattern matches the end of the value of parameter,
then the value of this substitution is the value of the parameter with
the matched portion deleted; otherwise the value of this parameter is
substituted. In the first form the smallest matching pattern is deleted
and in the latter form the largest matching pattern is deleted.
In the above, word is not evaluated unless it is to be used as the
substituted string, so that, 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 (It is not clear what this
means).
The following parameters are automatically set by the shell:
-
- #
-
The number of positional parameters in decimal.
- -
-
Flags supplied to the shell on invocation or by the set command.
- ?
-
The decimal value returned by the last synchronously executed command.
- $
-
The process number of this shell.
- !
-
The process number of the last background command invoked.
- _
-
The last argument of the previous command.
- ~
-
The shell reserves all variables beginning with a ~ for its own
internal use and these variables cannot be accessed by the user.
The following parameters are used by the shell:
-
- CDPATH
-
The search path for the cd command. (Note that because a colon is used
by MS-DOS to indicate a drive, a semi-colon is used to separate the path
names instead of a colon - this implies that the CDPATH variable must be set
using single or double quotes to surround the value).
- COLUMNS
-
This variable is contains the number of columns on the screen.
- COMSPEC
-
When the shell has to process an MS-DOS .bat or
OS/2 .cmd
file, it expects the file indicated by the value of this environment variable
to be an executable program capable of processing the MS-DOS .bat
or OS/2 .cmd file. The program is invoked with the arguments
/c file_name. COMSPEC is parsed and split on white space
to allow addition parameters to be passed to command processor. Thus the
default environment size could be set to 1000 by setting to command
/e:1000.
- EDITOR
-
If the value of this variable ends in emacs or vi, and the VISUAL
variable is not set, then the corresponding option is turned on.
- ENV
-
If this parameter is set, then parameter substitution is performed on the
value to generate the pathname of the script that will be executed when the
shell is invoked (See Invocation below). This file is typically used for
alias and function definitions.
- ETCPROFILE
-
If this parameter is set, it contains the full pathname of the
/etc/profile script which is executed at interactive startup when the
-0 option is given to the shell. If the parameter is not set, the
file /etc/profile on the root drive (see Initialisation File
is used.
- EXTENDED_LINE
-
This parameter pointers to a file which contains information for the shell
about how command lines are to be built for particular external programs and
how to convert from the format entered to the shell (see Command Line
Building).
- FCEDIT
-
The default editor name for the fc command.
- HISTFILE
-
The file where command history is saved across login sessions. The default
value is $HOME/history.sh.
- HISTSIZE
-
The number of commands normally stored for history, default 100.
- HOME
-
The default argument (home directory) for the cd command.
- IFS
-
Internal field separators, normally space, tab, and new-line.
- LINENO
-
This variable contains the current line number in the script being
processed.
- LINES
-
This variable contains the number of lines on the screen.
- MAIL
-
If this parameter is set to the name of a mail file and the
MAILPATH parameter is not set, the shell informs the user of
the arrival of mail in the specified file.
- MAILCHECK
-
This parameter specifies how often (in seconds) the shell will check for the
arrival of mail in the files specified by the MAILPATH or
MAIL parameters. If set to 0, the shell will check before each
prompt.
- MAILPATH
-
A semi-colon (;) separated list of file names. If this parameter is set,
the shell informs the user of the arrival of mail in any of the specified
files. Each file name can be followed by % and a message that will be
printed when the modification time changes. The default message is
"you have mail".
- OLDPWD
-
The previous working directory set by the cd command.
- OPTARG
-
The value of the last option argument processed by the getopts special
command.
- OPTIND
-
The index of the last option argument processed by the getopts special
command.
- OSMODE
-
The operating system under which the shell is running (0 - MS-DOS;
1 - OS/2; 2 - MS Windows NT).
- PATH
-
The search path for commands (see Execution below). The user may not
change PATH if executing under rsh. (Note that because a
colon is used by MS-DOS to indicate a drive, a semi-colon is used to
separate the path names instead of a colon - this implies that the PATH
variable must be set using single or double quotes to surround the value).
The Shell automatically converts Unix format PATH assignments
to MS-DOS format when appropriate. A assignment is converted if there
are no semi-colons, no \s and one or more colons. If there is only
one colon, it must not be the second character of the new value.
- PATHEXTS
-
The variable PATHEXTS contains the list of valid extensions for which
the shell should check when looking for an file to execute. This variable
allows the user to specify a function to execute if a file with an extension
in PATHEXTS is found (see Functions below).
- PWD
-
The present working directory set by the cd command.
- PS1
-
Primary prompt string, by default ``$ ´´.
- PS2
-
Secondary prompt string, by default ``> ´´.
- PS3
-
Selection prompt string used within a select loop, ``#? ´´.
- PS4
-
The value of this parameter is expanded for parameter substitution and precedes
each line of an execution trace. If omitted, the execution trace prompt is
``+ ´´.
- RANDOM
-
Each time this parameter is referenced, a random integer is generated. The
sequence of random numbers can be initialised by assigning a numeric value to
RANDOM.
- REPLY
-
This parameter is set by the select statement and by the read
special command when no arguments are supplied.
- SECONDS
-
Each time this parameter is referenced, the number of seconds since shell
invocation is returned. If this parameter is assigned a value, then the value
returned upon reference will be the value that was assigned plus the number of
seconds since the assignment.
- SHELL
-
When the shell is invoked, it scans the environment (see Environment
below) for this name. If it is found and there is an 'r' in the file name
part of its value, the shell becomes a restricted shell. The shell also
uses this variable to decide which program to spawn to interpret shell
scripts (see Execution below).
- SHMODE
-
The compilation mode of shell - 16 or 32 bit.
- STARTWINP
-
This variable, set by the user, contains the program to run to start a
MS Windows application when the shell is running under MS Windows. The
variable may contain parameters to that program as well. The shell assumes
that the parameters are separated by white space. If this variable is not
set, the shell will not start MS Windows applications when running under
MS Windows.
- VISUAL
-
If the value of this variable ends in emacs or vi, then the corresponding
option is turned on.
- TMP
-
The location of temporary files created by the shell. If this variable is
not defined, the Shell uses the HOME directory for temporary
files. Failing that, the root directory of the current drive is used.
- WINTITLE
-
Under OS/2, the name of the shell's window.
The shell gives default values to PATH, PS1,
PS2, SHELL, HOME and
IFS.
Alternation
The csh provides a filename expansion method known as alternation.
This has been added into this version of the ksh. When performing filename
substitution, you can get the shell to create a set of strings for you. For
example: exampl{a,b,c,d,e} will expand to exampla examplb
examplc exampld example. A common separated set of strings
in curly braces will be expanded into a set of strings that are passed into
the command. The strings are not sorted. The set of strings may contain
parameter substitutions.
Arithmetic Expansion
A string of the form $((exp)) is substituted with the value
of the arithmetic expression exp. exp is treated as if it were
within single quotes. See Arithmetic Evaluation below.
Blank Interpretation
After 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 Generation
Following substitution, each command word is scanned for the characters
*, ? and [. If one of these characters appears the word
is regarded as a pattern. The word is replaced with alphabetically
sorted file names that match the pattern. If no file name is found that
matches the pattern, the word is left unchanged. The character . at the
start of a file name or immediately following a /, as well as the
character / itself, must be matched explicitly. When matching
patterns for file names, the shell ignores the case of the pattern and the
file directory entries. Generated file names are always in lower case (for
FAT file systems). Under HPFS on OS/2, case is preserved.
-
- *
-
Matches any string, including the null string.
- ?
-
Matches any single character.
- [ ... ]
-
Matches any one of the enclosed characters. A pair of characters separated by
- matches any character lexically between the pair, inclusive. If the
first character following the opening ``[´´ is a
``!´´ any character not enclosed is matched.
If the shell has to open or create the file /dev/tty or /dev/null
(which are Unix special files), they are converted to the equivalent
MS-DOS file names (/dev/con and /dev/nul respectively). Any
user programs which could expect /dev/tty or /dev/null as
arguments must do its own mapping to the MS-DOS equivalents.
The shell checks for valid FAT filenames (single dot, not at the beginning).
Invalid dots are converted to ~. A warning message is displayed if the
shell detects an invalid file name.
Quoting
The following characters have a special meaning to the shell and cause
termination of a word unless quoted:
-
; & ( ) | ^ < > new-line space tab
A character may 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" ....
Arithmetic Evaluation
An ability to perform integer arithmetic is provided with the special command
let. Evaluations are performed using long arithmetic. Constants
are of the form base#n where base is a decimal number between two
and thirty-six representing the arithmetic base and n is a number in
that base. If base# is omitted then base 10 is used.
An arithmetic expression uses nearly the same syntax precedence, and
associatively of expression as C. The following set of operators, listed in
order of decreasing precedence, have been implemented:
- + ! ~ ++ -- |
unary minus/plus, logical NOT, complement, {pre, post}{in,de}crement
|
& | Logical AND
|
^ | Logical XOR
|
| | Logical OR
|
* / % | multiplication, division, remainder
|
+ - | addition, subtraction
|
<< >> | Logical shift left and right
|
<= >= < > | comparison
|
== != | equality inequality
|
&& | Logical AND
|
|| ^^ | Logical OR, XOR
|
? : | Ternary operator
|
= += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^=
| assignment
|
The operators &&, ||, &&= and ||= are short-circuiting
and only one of the latter two expressions in a ternary operator is evaluated.
Note the precedence of the logical AND, XOR and OR operators.
Sub-expressions in parentheses () are evaluated first and can be used to
override the above precedence rules.
Named parameters can be reference by name within an expression without
using the parameter substitution syntax.
Since many of the arithmetic operators require quoting, an alternative form of
the let command is provided. For any command which begins with a
((, all the characters until a matching )) are treated as a quoted
expression. More precisely, ((...)) is equivalent to let "...".
Prompting
When 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.
Many people like to have the shell provide them with useful information in
their prompt. To accommodate this, the shell recognises special sequences of
characters in the values of PS1 and PS2, and substitutes the
appropriate information for them. The special sequences and what they signify
are:
-
- %d
-
Place the current date, in the form DAY DD-MM-YY into the prompt.
- %e
-
Place the current event number (as defined by the history command) into
the prompt. If history evaluation has been turned off (via history -d),
no number will be substituted in (i.e. the %e will be removed).
- %n
-
Place the current working drive into the prompt.
- %p
-
Place the current working directory into the prompt.
- %t
-
Place the current time of day, in the form HH:MM into the prompt.
The time is on a 24 hour clock, i.e. 1:30 in the afternoon will be 13:30.
- %v
-
Place the operating system version number, in the form
OS name MM:MM into the prompt.
- %%
-
Place the character % into the prompt.
- \xxx
-
Place the character \xxx into the prompt. The processing of escape
sequences is the same as that for echo.
Some of these facilities are of more use than others.
Input/Output
Before a command is executed, its input and output may be redirected using a
special notation interpreted by the shell. The following may appear anywhere
in a simple-command or may precede or follow a command and are not
passed on to the invoked command; substitution occurs before word or
digit is used:
- <word
-
Use file word as standard input (file descriptor 0).
- >word
-
Use file word as standard output (file descriptor 1). If the file does
not exist it is created; otherwise, it is truncated to zero length.
- >>word
-
Use file word as standard output. If the file exists output is appended
to it (by first seeking to the end-of-file); otherwise, the file is created.
- <<[-]word
-
The shell input is read up to a line that is the same as word, or to an
end-of-file. The resulting document becomes the standard input. If any
character of word is quoted, no interpretation is placed upon the
characters of the document; otherwise, parameter and command substitution
occurs, (un-escaped) \new-line is ignored, and \ must be used to
quote the characters \, $, `, and the first character of
word. If - is appended to <<, all leading tabs are
stripped from word and from the document.
- <&digit
-
Use the file associated with file descriptor digit as standard input.
Similarly for the standard output using >&digit.
- <&-
-
The standard input is closed. Similarly for the standard output using
>&-.
- n<>word
-
causes the file word to be opened on file descriptor n for both
reading and writing. The file must already exist.
If any of the above is preceded by a digit, the file descriptor which will be
associated with the file is that specified by the digit (instead of the
default 0 or 1). For example:
-
... 2>&1
associates file descriptor 2 with the file currently associated with file
descriptor 1.
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 were reversed, file descriptor 2 would be
associated with the terminal (assuming file descriptor 1 had been) and file
descriptor 1 would be associated with file xxx .
The environment for the execution of 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.
Environment
The 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. 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). A parameter may be
removed from the environment with 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 may be augmented by prefixing it
with one or more assignments to parameters. Thus:
-
TERM=450 cmd args
and
-
(export TERM; TERM=450; cmd args)
are equivalent (as far as the execution of cmd is concerned).
If the -k flag 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 c:
-
echo a=b c
set -k
echo a=b c
Signals
The INTERRUPT and QUIT signals for an invoked command are
ignored if the command is followed by &; 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).
Command Re-entry
The text of the last HISTSIZE (default: 100) commands entered
from a terminal device is saved in a history file. The file
$HOME/history.sh is used if the HISTFILE variable
is not set. The special command fc
is used to list or edit a portion of this file. The portion of the file to be
edited or listed can be selected by number or by giving the first character or
characters of the command. A single command or range of commands can be
specified. If you do not specify an editor program as an argument to
fc, the value of the parameter FCEDIT is used. The edited
command is printed and re-executed upon leaving the editor. The editor name
- is used to skip the editing phase and to re-execute the command. In
this case a substitution parameter of the form old=new can be used
to modify the command before execution. For example, if r is aliased to
`fc -e -', typing `r bad=good c' re-executes the most recent
command that starts with the letter c and replaces the first occurrence
of the string bad with the string good.
History
When reading input from an interactive terminal and vi, emacs or
gmacs input editing mode has not been selected (see In-line Editing
Options), a ``!´´ at the
start of a line signals to the shell that it should attempt to perform a history
substitution. A history substitution is a short-hand method which allows the
user to recall a previous command for execution or editing. The recalled
command is placed in the command line for editing or passing to the rest of
the shell for normal processing. A history substitution takes the form:
-
! [ ! | str | num ] terminator
!! will place the previous command in the command line.
!num will place the history command with the specified number
in the command line. !str will find the most recent command
line that started with the characters in str.
The terminator determines what action is performed after the history
line has been found. If the original history command is entered using the
<return> key, the new command line is passed directly to the shell.
If the <end> key is pressed, the new command line can be edited in the
manner described below.
Command Line Editing
When reading input from an interactive terminal, certain keystrokes allow
the current input line to be edited. The following keystrokes
corresponding to the following functions are defined in the initialisation
file sh.ini. The keywords in the initialisation file which provide
the functions are listed below:
- Right
-
Move the cursor right one character
- WordRight
-
Move the cursor right one word
- Left
-
Move the cursor left one character
- WordLeft
-
Move the cursor left one word
- Previous
-
Get the previous command from the history file
- Next
-
Get the next command from the history file
- Insert
-
Toggle insert/overwrite mode (note the shape of the cursor changes to
indicate the current mode)
- DeleteRight
-
Delete the current character unless the cursor is at the end of line when
no action is taken
- Start
-
Move the cursor to the start of the command
- Complete
-
Attempt to complete the filename. The shell attempts to complete the file
name at the current cursor position. The file name is delimited by white
space characters. If the shell is unable to complete the file name (ie no
match can be found in the appropriate directory), the bell is rung. If a
single match is found, the new file name is displayed. If multiple matches
are found, the file name is replaced by the longest non-unique part of the
file name and the bell is rung.
- End
-
Move the cursor to the end of the command, unless the first character of
the command is a !, in which case the appropriate history search is
done. The cursor is placed at the end of the command line.
- Flush
-
Delete to the end of the line
- ScanBackward
-
Search backwards from the current history command for the next match against
the last history request or the string currently in the command line if
there has been no previous history request.
- ScanForeward
-
Search forewards from the current history command for the next match against
the last history request or the string currently in the command line if
there has been no previous history request.
- Clear
-
Erase the complete line.
- ClearScreen
-
Clears the complete screen. This function is only available under OS/2.
- Directory
-
Display the file name list matching the partially entered file name under
the cursor. If no matches are found the bell is rung. To display the
whole directory, enter the directory name followed by a slash /.
After the directory listing has been displayed, the entered command line is
redisplayed.
- DeleteLeft
-
Delete the character to the left of the cursor.
- Return
-
Execute the command line, unless the first character of the command is a
!, in which case the appropriate history processing is done. This
is the actual key pressed and cannot be modified by the initialisation file.
- Jobs
-
Print a list of the child processes of the shell. This function is only
available under OS/2.
- Transpose
-
Transpose the two characters under the cursor.
- Quote
-
Disable any special processing for the next keystroke.
In-line Editing Options
Normally, each command line entered from a terminal device is simply typed
followed by a new-line (`RETURN' or `LINE FEED'), see previous section. If
the vi option is active, the user can edit the command line. To be in
this edit mode set
the vi option. An editing option is automatically selected each time
the VISUAL or EDITOR variable is assigned a value
ending in either of these option names.
The editing mode implements a concept where the user is looking through a
window at the current line. The window width is the value of
COLUMNS if it is defined, otherwise 80. If the line is
longer than the window width
minus two, a mark is displayed at the end of the window to notify the user.
As the cursor moves and reaches the window boundaries the window will be
centred about the cursor. The mark is a > (<, *) if the
line extends on the right (left, both) side(s) of the window.
The search commands in each edit mode provide access to the history file.
Only strings are matched, not patterns, although a leading ^ in the
string restricts the match to begin at the first character in the line.
Vi Editing Mode
There are two typing modes. Initially, when you enter a command you are in
the input mode. To edit, the user enters control mode by typing ESC
(\033) and moves the cursor to the point needing correction and then
inserts or deletes characters or words as needed. Most control commands
accept an optional repeat count prior to the command.
In edit mode, the key mappings defined in the initialisation file are mapped
onto the appropriate vi edit command.
Input Edit Commands
By default the editor is in input mode.
-
- backspace
-
Deletes previous character.
- Ctrl-W
-
Deletes the previous blank separated word.
- Ctrl-D
-
Terminates the shell.
- Ctrl-V
-
Escapes the next character. Editing characters can be entered in a command
line or in a search string if preceded by a Ctrl-V. The Ctrl-V
removes the next character's editing features (if any).
- \
-
Escapes the next editing character.
Motion Edit Commands
These commands move the cursor:
-
- [Count]l
-
Moves the cursor forward (right) one character.
- [Count]w
-
Moves the cursor forward one alphanumeric word.
- [Count]W
-
Moves the cursor to the beginning of the next word that follows a blank.
- [Count]e
-
Moves the cursor to end of the current word.
- [Count]E
-
Moves the cursor to end of the current blank-separated word.
- [Count]h
-
Moves the cursor backward (left) one character.
- [Count]b
-
Moves the cursor backward one word.
- [Count]B
-
Moves the cursor to the previous blank-separated word.
- [Count]|
-
Moves the cursor to the column specified by the count parameter.
- [Count]fc
-
Finds the next character c in the current line.
- [Count]Fc
-
Finds the previous character c in the current line.
- [Count]tc
-
Equivalent to f followed by h.
- [Count]Tc
-
Equivalent to F followed by l.
- [Count];
-
Repeats for the number of times specified by the count parameter the
last single-character find command: f, F, t, or T.
- [Count],
-
Reverses the last single-character find command the number of times specified
by the count parameter.
- 0
-
Moves the cursor to start of line.
- ^
-
Moves the cursor to first non-blank character in line.
- $
-
Moves the cursor to end of line.
Search Edit Commands
These commands access your command history:
-
- [Count]k
-
Fetches the previous command. Each time k is entered, the previous
command is accessed.
- [Count]-
-
Equivalent to k.
- [Count]j
-
Fetches the next command. Each time j is entered, the next command
is accessed.
- [Count]+
-
Equivalent to j.
- [Count]G
-
Fetches the command whose number is specified by the count parameter.
The default is the least recent history command.
- /String
-
Searches backward through history for a previous command containing the
specified string. The string is terminated by a RETURN or
new-line character. If the specified string is preceded by a ^ (caret),
the matched line must begin with string. If the value of the string
parameter is null, the previous string is used.
- ?String
-
Same as /String except that the search is in the forward direction.
- n
-
Searches for the next match of the last pattern to / or ? commands.
- N
-
Searches for the next match of the last pattern to / or ? commands,
but in the opposite direction. Searches history for the string entered
by the previous / command.
Text Modification Edit Commands
These commands modify the line:
-
- a
-
Enters the input mode and enters text after the current character.
- A
-
Appends text to the end of the line. Equivalent to $a.
-
-
[Count]cMotion
- c[Count]Motion
-
Deletes the current character through the character to which the motion
parameter specifies to move the cursor, and enters input mode. If the value
of the motion parameter is c, the entire line is deleted and the
input mode is entered.
- C
-
Deletes the current character through the end of the line and enters input
mode. Equivalent to c$.
- S
-
Equivalent to cc.
- D
-
Deletes the current character through the end of line. Equivalent to d$.
-
-
[Count]dMotion
- d[Count]Motion
-
Deletes the current character up to and including the character specified by
the motion parameter. If motion is d, the entire line is
deleted.
- i
-
Enters the input mode and inserts text before the current character.
- I
-
Inserts text before the beginning of the line. Equivalent to 0i.
- [Count]P
-
Places the previous text modification before the cursor.
- [Count]p
-
Places the previous text modification after the cursor.
- R
-
Enters the input mode and types over the characters on the screen.
- [Count]rc
-
Replaces the number of characters specified by the count parameter,
starting at the current cursor position, with the characters specified by
the c variable. Advances the cursor after the characters are replaced.
- [Count]x
-
Deletes the current character.
- [Count]X
-
Deletes the preceding character.
- [Count].
-
Repeats the previous text modification command.
- [Count]~
-
Inverts the case of the number of characters specified by the count
parameter, starting at the current cursor position, and advances the cursor.
- [Count]_
-
Causes the word specified by the count parameter word of the previous
command to be appended, and enters input mode. The last word is used if the
count parameter is omitted.
- *
-
Appends an * (asterisk) to the current word and attempts filename
substitution. If no match is found, it rings the bell. Otherwise, the word
is replaced by the matching pattern and input mode is entered.
- \
-
File-name completion. Replaces the current word with the longest common
prefix of all file names matching the current word with an asterisk appended.
If the match is unique, a / (slash) is appended if the file is a
directory and a space is appended if the file is not a directory.
Other Edit Commands
Other miscellaneous edit commands include:
-
-
-
[Count]yMotion
- y[Count]Motion
-
Yanks the current character through the character to which the motion
parameter specifies to move the cursor and puts these characters into the
delete buffer. The text and cursor are unchanged.
- Y
-
Yanks from the current position to the end of the line. Equivalent to y$.
- u
-
Undoes the last text-modifying command.
- U
-
Undoes all the text-modifying commands performed on the line.
- [Count]v
-
Returns the command fc -e ${VISUAL:-${EDITOR:-vi}} count in the
input buffer. If the count parameter is omitted, then the current line
is used.
- Ctrl-L
-
Line-feeds and prints the current line. Has effect only in control mode.
- Ctrl-J
-
(New line) Executes the current line, regardless of the mode.
- Ctrl-M
-
(Return) Executes the current line, regardless of the mode.
- #
-
Sends the line after inserting a # (hash sign) in front of the line.
Useful for causing the current line to be inserted in the history without
being executed.
- =
-
Lists the file names that match the current word as if an asterisk were
appended to it.
- @Letter
-
Searches the alias list for an alias named _Letter. If an alias of this name
is defined, its value is placed into the input queue for processing.
EMACS Editing Mode
When the emacs option is set, interactive input line editing is enabled.
This mode is slightly different from the emacs mode in AT&T's KornShell.
In this mode various editing commands (typically bound to one or more
control characters) cause immediate actions without waiting for a new-line.
Several editing commands are bound to particular control characters when
the shell is invoked; these bindings can be changed using the bind
command.
The following editing commands are available, where a caret indicates
the control character, and ^[ is the ASCII ESC character. Note
that editing command names are used only with the bind command.
The default bindings were chosen to resemble corresponding EMACS key bindings.
|
Editing command | Default | Function
|
|
prefix-3 | 0xE0 |
Introduces a 2-character command sequence. This prefix allows the user to
map PC function keys onto commands. The second character is the IBM scan
code value of the function key to be assigned. For example: F1 has a
scan code of ;; Ctrl-F1 has a scan code of ^; Shift-F1
has a scan code of T; Alt-F1 has a scan code of h.
|
beginning-of-line | Ctrl-A | Moves the cursor to start of line.
|
backward-char | Ctrl-B | Moves the cursor backward (left) one character.
|
eot-or-delete | Ctrl-D |
Acts as end-of-file if alone on a line; otherwise deletes current
character.
|
end-of-line | Ctrl-E | Moves the cursor to end of line.
|
forward-char | Ctrl-F | Moves the cursor forward one position.
|
abort | Ctrl-G |
Useful as a response to a request for a search-history pattern in order
to abort the search.
|
delete-char-backward | Ctrl-H |
Deletes the previous character.
|
newline |
Ctrl-M
Ctrl-J
|
Executes the current line.
|
kill-to-eol | Ctrl-K |
Deletes from the cursor to the end of the line. If preceded by a numerical
parameter whose value is less than the current cursor position, this editing
command deletes from the given position up to the cursor. If preceded by a
numerical parameter whose value is greater than the current cursor position,
this editing command deletes from the cursor up to given cursor position.
|
redraw | Ctrl-L | Line-feeds and print the current line.
|
down-history | Ctrl-N |
Fetches the next command line. Each time Ctrl-N is entered, the next command
line forward in time is accessed.
|
operate | Ctrl-O |
Executes the current line and fetches the next line relative to the
current line from the history file.
|
up-history | Ctrl-P |
Fetches the previous command. Each time Ctrl-P is entered, the previous
command back in time is accessed. Moves back one line when not on the first
line of a multiple line command.
|
search-history | Ctrl-R String |
Reverses search history for a previous command line containing the string
specified by the String parameter. If a value of zero is given, the
search is forward. The specified string is terminated by an Enter
or new-line character. If the string is preceded by a ^
(caret character), the matched line must begin with String. If the
String parameter is omitted, then the next command line containing the
most recent String is accessed. In this case, a value of zero reverses
the direction of the search.
|
transpose-chars | Ctrl-T |
Transposes the current character with the next character in emacs mode.
Transposes the two previous characters in gmacs mode.
|
kill-line | Ctrl-U | Deletes the entire input line.
|
kill-region | Ctrl-W | Kills from the cursor to the mark.
|
prefix-2 | Ctrl-X |
Introduces a 2-character command sequence.
|
pop-text | Ctrl-Y |
Restores the last item removed from line. (Yanks the item back to the line.)
|
search-char-forward | Ctrl-] c |
Moves the cursor forward on the current line to the indicated character.
|
search-char-backward |
Prefix-1 Ctrl-] c
|
Search backwards in the current line for the next keyboard character.
Moves the cursor backwards on the current line to the indicated character.
|
quote |
Ctrl-^
\
|
Escapes the next character. Editing characters can be entered in a command
line or in a search string if preceded by a quote command. The escape
removes the next character's editing features, if any.
|
eot | Ctrl-_ | Acts as an end-of-file.
|
comment-execute | Prefix-1 # |
Inserts a # (pound sign) at the beginning of the line and then execute
the line. This causes a comment to be inserted in the history file.
|
complete-list | Prefix-1 * |
Attempts file name substitution on the current word. An asterisk is appended
if the word doesn't match any file or contain any special pattern characters.
|
prev-hist-word
copy-last-arg
|
Prefix-1 .
Prefix-1 _
|
Inserts on the line the last word of the previous command. If preceded by a
numeric parameter, the value of this parameter determines which word to insert
rather than the last word. Note I/O redirections do not count as words of the
command.
|
beginning-of-history | Prefix-1 < |
Fetches the least recent (oldest) history line.
|
list | Prefix-1 = |
Prints a sorted, columnated list of file names (if any) that can complete the
partial word containing the cursor. Directory names have / post-pended
to them, and executable file names are followed by *.
|
end-of-history | Prefix-1 > |
Fetches the most recent (youngest) history line.
|
backward-word | Prefix-1 B |
Moves the cursor backward one word.
|
capitalise-word | Prefix-1 C |
Capitalises the current word.
|
delete-word-backward |
Prefix-1 Ctrl-H
Prefix-1 H
|
Deletes the previous word.
|
delete-word-forward | Prefix-1 D |
Deletes the current word.
|
prefix-1 | ESC |
Introduces a 2-character command sequence. Three introducers are
available.
|
complete | Prefix-1 ESC |
File-name completion. Replaces the current word with the longest common
prefix of all file names that match the current word with an asterisk appended.
If the match is unique, a / (slash) is appended if the file is a directory
and a space is appended if the file is not a directory.
|
forward-word | Prefix-1 F |
Moves the cursor forward one word (a string of characters consisting of only
letters, digits, and underscores).
|
downcase-word | Prefix-1 L |
Changes the current word to lowercase.
|
multiply | Prefix-1 M |
Multiplies the parameter of the next command by 4.
|
upcase-word | Prefix-1 U |
Change the current word to upper-case.
|
| Prefix-1 Digits |
Defines the numeric parameter. The digits are taken as a parameter to
the next command. The commands that accept a parameter are forward-char,
backward-char, backward-word, forward-word,
delete-word-forward, delete-char-forward,
delete-word-backward, delete-char-backward,
prev-hist-word, copy-last-arg, up-history, down-history,
search-history, upcase-word, downcase-word,
capitalise-word, upcase-char, downcase-char,
capitalise-char, kill-to-eol, search-char-forward and
search-char-backward.
|
capitalise-char | Prefix-1 c |
Capitalises the current character.
|
downcase-char | Prefix-1 l |
Change the character under the cursor to lower case.
|
push-text | Prefix-1 p |
Pushes the region from the cursor to the mark on the stack.
|
set-mark | Prefix-1 space | Sets a mark.
|
upcase-char | Prefix-1 u |
Change the character under the cursor to upper case.
|
yank-pop | Prefix-1 y |
Immediately after a yank, replaces the inserted text string with the
next previous killed text string.
|
exchange-point-and-mark |
Prefix-2 Ctrl-X
|
Interchanges the cursor and the mark.
|
jobs | Prefix-2 j |
Print a list of the current jobs (OS/2 only).
|
auto-insert | |
Simply causes the character to appear as literal input. (Most ordinary
characters are bound to this.)
|
delete-char-forward | |
Deletes the character after the cursor.
|
no-op | |
Does nothing.
|
clear-screen | | Clear the screen and print the current line.
|
reset | | Reset input, clearing the current line and yank buffers.
|
| Prefix-1 Ctrl-] Letter |
Search the alias list for an alias named _Letter. If an alias of this
name is defined, its value is placed into the input queue.
|
| Prefix-1 Letter |
Search the alias list for an alias named _Letter. If an alias of this
name is defined, its value is placed into the input queue. The Letter
parameter must not specify one of the escape functions.
|
Initialisation File
When the shell is run in interactive mode, the Command Line Editing keys
and other user configuration parameters are read from the initialisation
file sh.ini. This shell looks for this file in the same directory as
the sh executable which is running. It does not use the SHELL
environment variable or search the directories in the PATH
environment variable. At present, there are two types of entry in this
file: keyboard configuration; and others. The entry is contained in a
single line and consists of a keyword (in upper or lower case), white space,
an equals symbols, white space and one or two numeric values (see
strtol(3) for valid formats where base parameter is zero),
followed by an end of line character.
For the keyboard entries, the numeric values give the MS-DOS Function
8 (Console Input without Echo) return values for that entry. Note that
extended codes (function keys) require two calls to this function. The
first call returns zero and the second the extended code. In the
configuration file, a first numeric value of zero indicates a extended code
and must be followed by a second value. The shell also supports the use of
the ALT key in combination with another key. In this case, the first
value contains 0xff, that selects ALT key, and the second key
contains the appropriate scan code for the key required. The program
showkey can be used to determine the scan codes required.
A non-zero first numeric value must not be followed by anything else on the
line.
Other entries must only have one numeric value. A zero value disables the
function and a non-zero value enables the function. At present, there are
two other functions:
- Bell
-
Enable/disable warning bells
- HalfHeight
-
Use full or halfheight block cursor to indicate Insert mode
- InsertMode
-
Set the default insert mode on or off
- InsertCursor
-
Enable/disable the insert mode cursor.
- RootDrive
-
Determines the root drive from which to read /etc/profile.
- EOFKey
-
Determines the End-of-File key.
Invalid lines or lines beginning with a # are ignored.
The following table gives the list of valid keywords and their default
values:
Keyword | First numeric | Second numeric | Actual Key
|
|
KEYBOARD ENTRIES | | |
|
ScanBackward | 0 | 0x49 | PAGE UP
|
ScanForeward | 0 | 0x51 | PAGE DOWN
|
Previous | 0 | 0x48 | UP ARROW
|
Next | 0 | 0x50 | DOWN ARROW
|
Left | 0 | 0x4b | LEFT ARROW
|
Right | 0 | 0x4d | RIGHT ARROW
|
WordRight | 0 | 0x74 | Control RIGHT ARROW
|
WordLeft | 0 | 0x73 | Control LEFT ARROW
|
Start | 0 | 0x47 | HOME
|
Clear | 0 | 0x76 | Control PAGE DOWN
|
Flush | 0 | 0x75 | Control END
|
End | 0 | 0x4f | END
|
Insert | 0 | 0x52 | INSERT
|
DeleteRight | 0 | 0x53 | DELETE
|
DeleteLeft | 0x08 | | BACKSPACE
|
Complete | 0 | 0x77 | Control HOME
|
Directory | 0 | 0x0f | Shift TAB
|
ClearScreen | 0 | 0x84 | Control PAGE UP
|
Jobs | 0 | 0x68 | ALT F1
|
Transpose | 0x14 | | Control T
|
Quote | 0x11 | | Control Q
|
|
OTHER FUNCTIONS | | |
|
Bell | 0 | |
|
HalfHeight | 0 | |
|
InsertMode | 0 | |
|
InsertCursor | 1 | |
|
RootDrive | 3 | |
|
EOFKey | 0x1a | |
|
|
Execution
Each 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
semi-colon (;). The default path is .;c:/bin;c:/usr/bin (specifying
the current directory, c:/bin, and c:/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 semi-colon delimiters
anywhere else in the path list. If the command name contains a / or
starts with x: (where x is a drive letter) the search path is not used;
such commands will not be executed by the restricted shell. Otherwise, each
directory in the path is searched for an executable file. Executable files
are indicated by a .exe or .com extension. This extension is automatically
supplied by the shell and not have to be entered by the user.
If the file with a .com or .exe extension cannot be found in the
directory, the file is opened and first 512 characters are read. If there are
no characters in the block with a value in the range 0 to 7, the file is
assumed to be a script file containing shell commands. Note that the shell
will check the file and if that file does not exist or is not a script, it
will try the file with an extension of .sh or .ksh. If a
.sh or .ksh file is found, that will be processed. A sub-shell
(given by the environment variable SHELL) is spawned to read
it.
If the script file starts with the a line of the form #! interpreter
[arguments], the interpreter is invoked instead of the shell
to process the script. Optional arguments can be supplied in the script
file which are passed before the name of the script file. Thus, if the
file demo contained the following string as the first line
-
#! perl -sP
Entering demo name would be equivalent to entering the perl -sP name
at the command prompt. Note that no other processing of the first line
other that the separation (by white space) into arguments is done. Note
that if the interpreter is either /bin/sh or /bin/ksh,
the value of the SHELL environment variable is used to execute the
script.
If none of the above conditions for a executable file are detected and a file
with a .bat extension exists in the directory, the command processor given by
the COMSPEC environment variable is spawned to process the file. This
is normally the standard MS-DOS command.com or OS/2
cmd.exe processor.
A parenthesised command is also executed in a sub-shell.
Under MS-DOS or OS/2, the shell looks at the type of the program which is
about to be executed. If it is an MS Windows program, the shell will
automatically start MS Windows, unless it is already running. If
MS Windows is already running, the shell will not start the program.
Command Line Building
The file pointed to by the EXTENDED_LINE parameter contains information
which instructs the shell on how to create the command line for a particular
program from the information entered to the shell. If the program name is
not found in this file, the standard MS-DOS or OS/2 mechanisms are
used with no special processing.
The file is scanned prior to the execution of an external command. An entry
in this file is contained in a single line and consists of a program name
(in upper or lower case), white space, an equals symbol, white space and
the program type followed by up to four optional values, followed by an end of
line character. The value tells the shell how to build the command line
and the optional values provide additional information. The valid
program types are (note that invalid entries cause a line to be ignored)
given below. These program types must appear as the first value
following the equals. Otherwise, they are ignored. An empty program
types may be empty to only select one or more of the optional values.
Under OS/2, by default the shell generates the command line using the
format specified by Eberhard Mattes's EMX interface. This is makes no
difference to programs which do not support the interface.
-
- unix
-
This program can process the command line using the indirect command file
character @. When a program, which can process this format, finds a
command line parameter starting with a @ in the command line, it treats
the rest of the parameter as a file and reads the command line parameters
from that file (one per line, the end of line characters can be escaped by
preceding with a \). Examples of this functionality include the
Standard Linker and Librarian.
The file name is set up in UNIX format (using / as the directory
separators).
This functionality allows the user to get round the 127 byte command line
length limit of MS-DOS. A sample version of the code to process wild
cards and indirect command files is included with the source of the shell in
the file stdargv.c.
- dos
-
This program can process the command line using the indirect command file
character @. The file name is set up in DOS format (using
\s as the directory separators).
- environ
-
The command line is passed to the external program in the environment
variable specified by the first optional value. The optional second
value which is numeric, gives the parameter separator character to be used
(see strtol(3) for valid formats where base parameter is zero).
If this second value is missing or evaluates to zero, space is used.
The following optional values described below may be used after either
unix or dos or by themselves:
-
- switch
-
The optional value switch causes the program parameters to
be converted from UNIX format to MS-DOS format. This means that
parameters beginning with an - have it converted to a /.
For all other parameters, /s are converted to \s. This option
is not applied to quoted parameters or escaped characters.
This functionality allows ease of entry of MS-DOS commands which expect
MS-DOS directory separators which the shell interprets as the escape
character (not that the underlying MS-DOS really cares).
- export
-
The optional value export causes the marked environment variables to
be converted from UNIX format to MS-DOS format. This is
equivalent to setting the -M flag for this program only.
- noexpand
-
The optional value noexpand disables file name generation when building
the command line (also see set command).
- noswap
-
The optional value noswap disables swapping for the command. This
may speed up the execution of small commands.
- noquote
-
The optional value noquote stops the shell from escaping double quotes
in the command line before they are passed to the command. Double quotes
processed by some programs.
- ignoretype
-
The optional value ignoretype stops the MS-DOS version of the shell
deciding not to execute foreign (non MS-DOS) executables. The headers
of some .EXE files record incorrectly the operating system and type of
program. This option only applies to the MS-DOS version of the shell.
- pipetty
-
The optional value pipetty causes the shell to set up the environment
such that child shells created by this program will treat Pipes as TTYs.
This feature is mainly to support EMACS under OS/2, but may prove useful to
other programs in a somewhat bizarre set of circumstances. This feature is
not support under the MS-DOS version of the shell.
- quotewild
-
The optional value quotewild causes the shell to quote wild cards in
the command line to the program. The default is not to quote wild cards.
Functions
The function keyword, described in the Commands section above, is
used to define shell functions. Shell functions are read in and stored
internally. Alias names are resolved when the function is read. Functions
are executed like commands with the arguments passed as positional parameters.
(See Execution above).
Functions execute in the same process as the caller and share all files and
present working directory with the caller. Traps caught by the caller are
reset to their default action inside the function. A trap condition that is
not caught or ignored by the function causes the function to terminate and the
condition to be passed on to the caller. A trap set on EXIT inside a function
is executed after the function completes.
Ordinarily, variables are shared between the calling program and the function.
However, the typeset special command used within a function defines local
variables whose scope includes the current function and all functions it calls.
The special command return is used to return from function calls. Errors
within functions return control to the caller.
Function identifiers can be listed with the function special command.
The text of functions will also be listed. Function can be undefined with
the unfunction special command.
Ordinarily, functions are unset when the shell executes a shell script.
Functions that need to be defined across separate invocations of the shell
should be placed in the ENV file.
The shell has an enhancement that allows it to process scripts, etc. by
recognising their file extension (the character string following the
last period). If the shell recognises the extension, it will invoke
the function named after the extension, if it exists (for example:
the command demo.c will invoke the function .c). The
variable PATHEXTS contains the list of valid extensions (and must
include the default extensions (.exe, .com, .bat
or .cmd, .sh, .ksh and no extension). Note that
functions cannot be set up for .exe or .com.
The order in which the extensions appear in PATHEXTS determines the
order in which the shell will search for a file with the appropriate extension.
If the shell finds a file with a matched extension and a function exists,
the function is invoked with parameter 0 set to the full pathname of the
file. The rest of the parameters to the function are set up as for normal
functions. Beware of invoking recursive functions.
Jobs
Under OS/2, an interactive shell associates a job with each
pipeline. It keeps a table of current jobs, printed by the jobs
command, and assigns them small integer numbers. When a job is started
asynchronously with &, the shell prints a line that looks like:
-
[1] 1234
indicating job number 1 was started asynchronously and had one (top-level)
process whose process ID was 1234.
There are several ways to refer to jobs in the shell. A job can be referred
to by the process id of any process in the job or by one of the following:
-
- %number
-
The job with the given number.
- %string
-
Any job whose command line begins with string.
- %?string
-
Any job whose command line contains string.
- %%
-
Current job.
- %+
-
Equivalent to %%.
- %-
-
Previous job.
The shell learns when a process changes state. It informs the user when
a job terminates, but only just before it prints a prompt.
If you try to leave the shell while jobs are running or stopped, you are
warned, You have running jobs. You may use the jobs command to
identify them. If you immediately try to exit again, the shell will not
warn you a second time.
Special Commands
Input/output redirection is permitted for these commands. File descriptor 1
is the default output location.
- :
-
No effect; the command does nothing. A zero exit code is returned.
- letter:
-
Select the drive specified by letter.
- . file
-
Read and execute commands from file and return. The search path
specified by PATH is used to find the directory containing file.
- alias [ -t ] [ name[=value ] ... ]
-
Alias with no arguments prints the list of aliases in the form
name=value on standard output. An alias is defined for each
name whose value is given. A trailing space in value
causes the next word to be checked for alias substitution. The -t
flag is used to set and list tracked aliases. The value of a tracked
alias is the full pathname corresponding to the given name. The value
becomes undefined when the value of PATH is reset but the aliases
remained tracked. Without the -t flag, for each name in the
argument list for which no value is given, the name and
value of the alias is printed. Alias returns zero unless a name
is given for which no alias has been defined.
- bind -m [ string ] = [ editing-command ]
-
Bind with no arguments prints the list of EMACS key bindings in the form
name=value on standard output.
The specified editing command is bound to the given string, which
should consist of a control character (which may be written using ``caret
notation'' ^x), optionally preceded by one of the two prefix
characters. Future input of the string will cause the editing
command to be immediately invoked. Three prefix characters (normal ESC
and ^X) are supported.
If the -m flag is supplied, the specified input string will
afterwards be immediately replaced by the given editing-command string,
which may contain editing commands.
- break [ n ]
-
Exit from the enclosing for or while loop, if any. If n is
specified, break n levels.
- builtin [ args ... ]
-
Force the selection of the builtin version of a command. The builtin
shell command selected by the first args value is executed with the
parameters defined by the remaining argss. If no arguments are given,
a list of all builtin commands is printed.
If the first argument is one of the following, the processing of the
builtin command in the following arguments are changed as indicated:
-
- -a
-
Set the following builtin commands to use builtin version in preference to
any function or external versions.
- -d
-
Set the following builtin commands to use the function or external version
in preference to the builtin version.
- -s
-
Display the current status of the following builtin commands.
- continue [ n ]
-
Resume the next iteration of the enclosing for or while loop. If
n is specified, resume at the n-th enclosing loop.
-
-
cd [ -LP ] [ arg ]
- cd search replace
-
This command can be in either of two forms. In the first form it changes
the current directory to arg. The shell parameter HOME is
the default arg. The shell parameter CDPATH defines the search
path for the directory containing arg. Alternative directory names are
separated by a semi-colon (;). The default path is <null>
(specifying the current directory). Note that the current directory is
specified by a null path name, which can appear immediately after the equal
sign or between the semi-colon delimiters anywhere else in the path list.
If arg begins with a / or x: (where x is a drive letter),
the search path is not used. Otherwise, each directory in the path is searched
for arg. The cd command may not be executed by rsh.
The -L option (default) preserves logical naming when treating
substituted drives (see SUBST(1)). cd -L .. moves the current
directory one path component closer to the root directory. The -P
option preserves the physical path when treating substituted drives.
cd -P .. changes the working directory to the parent directory of the
current directory. These options are only available under the MS-DOS 16 bit
version.
In the second form, cd substitutes the string replace for the
string search in the current directory name, PWD and tries to
change to this new directory.
Note that the name chdir is an builtin alternative name for cd,
allowing the user to set up aliases for cd and still have access to the
change directory functionality.
- detach program [ args ]
-
This command (which is only available under OS/2) starts and
simultaneously detaches an OS/2 program from the shell. Any
program that is started with detach command must be able to
process independently outside the control of the shell. Builtin shell
commands and functions cannot be detached.
- echo [ arg ... ]
-
Echo arguments. Echo writes its arguments separated by blanks and
terminated by a new-line on the standard output. It also understands C-like
escape conventions; beware of conflicts with the shell's use of \:
-
- \b
-
backspace
- \c
-
print line without new-line
- \f
-
form-feed
- \n
-
new-line
- \r
-
carriage return
- \t
-
tab
- \v
-
vertical tab
- \\
-
backslash
- \n
-
the 8-bit character whose ASCII code is the 1-, 2- or 3-digit octal
number n, which must start with a zero.
Echo is useful for producing diagnostics in command files and for
sending known data into a pipe.
- eval [ arg ... ]
-
The arguments are read as input to the shell and the resulting command(s)
executed.
- exec [ arg ... ]
-
The command specified by the arguments is executed in place of this shell
without creating a new process. Input/output arguments may appear and, if no
other arguments are given, cause the shell input/output to be modified.
- exit [ n ]
-
Causes a shell to exit with the exit status specified by n.
If n is omitted the exit status is that of the last command executed
(an end-of-file will also cause the shell to exit.)
- export [ name[=value] ... ]
-
The given names are marked for automatic export to the environment
of subsequently-executed commands. If no arguments are given, a list of all
names that are exported in this shell is printed. Function names may not
be exported.
- false
-
No effect; the command does nothing. A non-zero exit code is returned.
-
-
fc [ -e EditorName ] [ -nlr ] [ First [ Last ] ]
- fc -e - [ Old=New ] [ Command ]
-
In the first form, a range of commands from First to Last is
selected from the last 100 commands that were typed at the terminal. The
First and Last parameters can be specified as a number or as a
string. A string locates the most recent command starting with the given
string. A negative number is used as an offset to the current command number.
If Last is not specified, then it is set to First. If First
is not specified, the default is the previous command for editing and
-16 for listing.
-
- -l
-
Lists the commands to standard output.
- -r
-
Reverses the order of the commands in the list.
- -n
-
Suppresses command numbers when listing.
-
If the -l flag is not specified, the editor program specified by
EditorName is invoked on a file containing these key-board commands.
If EditorName is not supplied, then the value of the FCEDIT
parameter is used as the editor. When editing is complete, the edited
command(s) is executed.
In the second form, the specified command is carried out again after the
Old=New substitution is performed.
- functions [ name ... ]
-
The functions given by names are printed. If no arguments are given, a
all the functions are displayed.
- getopts optstring name [ arg ... ]
-
Checks arg for legal options. If arg is omitted, the
positional parameters are used. An option argument begins with a + or
a -. An option not beginning with + or - or the argument
-- ends the options. optstring contains the letters that
getopts recognises. If a letter is followed by a :, that option
is expected to have an argument. The options can be separated from the
argument by blanks.
getopts places the next option letter it finds inside variable
name each time it is invoked, with a + prepended when arg
begins with a +. The index of the next arg is stored in
OPTIND. The option argument, if any, gets stored in
OPTARG,
A leading : in optstring causes getopts to store the letter
of an invalid option in OPTARG, and to set name to
? for an unknown option and to : when a required option is
missing. Otherwise, getopts prints an error message. The exit status
is non-zero when there are no more options.
- history [ -deils ]
-
The history command, with no arguments, will print all the commands that
are currently saved in the shell's history buffers. As new commands are
executed, and space in the buffers runs out, old commands will be deleted. The
history commands prints out the stored commands with sequence numbers.
Negative numbered commands, through command number zero, are commands that were
retrieved from the saved history file. Commands starting at one were entered
during the current login session. If a saved command contains embedded
newlines, these will be printed out as the sequence \n, so that
individual command stay on one line.
The arguments changes the way the shell processes history information as
follows:
-
- -d
-
Disable the saving of commands in the history file.
- -e
-
Enable the saving of commands in the history file.
- -i
-
Initialise the history file.
- -l
-
Load the history from the file given by the HISTFILE environment variable.
- -s
-
Save the history to the file given by the HISTFILE environment variable.
- jobs [ -lp | [ -P job ] ]
-
This command (which is only available under OS/2) lists the active jobs;
or all active jobs if job is omitted. The -l options lists process id's
in addition to the normal information. The -p flag lists all the child
processes of the current shell, displaying their process ID and thread count.
The -P id option lists all the child processes of the specified process
or job. See Jobs for a description of the format of job.
- kill [ -sig ] [ process | %jobid ] ...
-
This command (which is only available under OS/2) sends either the
TERM (terminate) signal or the specified signal to the specified
processes. Signals are given by name, which are listed by
'kill -l'. If the process number begins with a %, the
signal is sent to the job referenced. See Jobs for a description of
the format of a job.
- let [ arg ... ]
-
Each arg is an arithmetic expression to be evaluated. All calculations
are done as long integers and no check for overflow is performed. See
Arithmetic Evaluation above for a description of arithmetic expressions..
The return code is 0 if the value of the last expression is non-zero, and 1
otherwise.
- msdos [ name[=value] ... ]
-
The given names are marked msdos format and if the -M flag
is set, the values of the these names are exported to child processes
with any slashes in the value replaced by \s. If no arguments are
given, a list of all msdos names is printed.
- print [ -Rnprs ] [ -u unit ] [ args ... ]
-
The shell output mechanism. With no flags or with flag - or -- the args
are printed on standard output as described by the echo command.
-
- -R
-
Prints in the raw mode, in which the escape conventions of the echo
command are ignored. The -R option prints all subsequent args
and options other than -n.
- -n
-
Prevents a new-line from being added to the output.
- -p
-
-p flag has not effect and is defined for compatibility.
- -r
-
Prints in the raw mode, in which the escape conventions of the echo
command are ignored.
- -s
-
Writes the args to the history file instead of to standard output.
- -u unit
-
Specifies a one digit file descriptor unit number on which the output is
placed. The default is 1.
- pwd [ -LP ] [ drive ... ]
-
Print the current working directory. If drive is present, the
current working directory on each of the drives is printed. drive
contains a string of drive letters, no colons are required.
The -L option (default) preserves the logical meaning of the current
directory and -P preserves the physical meaning of the current directory
if it is on a substituted drive (see cd and SUBST(1)). This
option is only available under the MS-DOS 16bit version.
- read [ -prs ] [ -u unit ] [ name?prompt ] [ name ... ]
-
The shell input mechanism. One line is read and is broken up into words using
the characters in IFS as separators. In raw mode, -r, a \
at the end of a line does not signify line continuation. The first word is
assigned to the first name, the second word to the second name,
etc., with leftover words assigned to the last name. If the -s flag
is present, the input will be saved as a command in the history file. The
-p flag has not effect and is defined for compatibility. The flag
-u can be used to specify a one digit file descriptor unit to read
from. The file descriptor can be opened with the exec special command.
The default value of unit is 0. If name is omitted then
REPLY is used as the default name. If the first argument contains a
?, the remainder of this word is used as a prompt when the shell is
interactive. If the given file descriptor is open for writing and is a
terminal device then the prompt is placed on this unit. Otherwise the prompt
is issued on file descriptor 2. The return code is 0 unless an end-of-file
is encountered.
- readonly [ name[=value] ... ]
-
The given names are marked readonly and the values of the these
names may not be changed by subsequent assignment. If no arguments are
given, a list of all readonly names is printed.
- return [ n ]
-
Causes a function to exit with the return value specified by n. If
n is omitted, the return status is that of the last command executed.
- set [ [-|+]aefkmntuvx ] [ -o option ] [ arg ... ]
-
-
- -a
-
Mark variables which are modified or created for export.
- -e
-
Exit immediately if a command exits with a non-zero exit status.
- -f
-
Disable file name generation
- -h
-
Each command becomes a tracked alias when first encountered.
- -k
-
All keyword arguments are placed in the environment for a command, not just
those that precede the command name.
- -m
-
Background jobs will run in a separate process group and a line will print
upon completion. The exit status of background jobs is reported in a
completion message. This only applies to OS/2. The programs are detached
from the current process group.
- -n
-
Read commands but do not execute them.
- -o option
-
The argument that follows this option can be one of the following option names:
-
- allexport
-
Same as -a.
- bell
-
Enable alarm bell on errors
- break
-
Enable the extended SIGINT checking (see BREAK [ ON | OFF ]
under COMMAND.COM). This option is only available under MS-DOS.
- emacs
-
Select emacs-like command line editing mode.
- errexit
-
Same as -e.
- gmacs
-
Select gmacs-like command line editing mode.
- halfheight
-
Set cursor to halfheight when in insert mode. If off, a full height cursor
is used.
- ignorecase
-
Under OS/2, on non-FAT (ie case retentive) file systems, the shell
will match file names ignoring case. Normally, the matches are case
sensitive even though the file system is only case retentive.
- ignoreeof
-
The shell will not exit on end-of-file. The command exit must be used.
- insertmode
-
Set the default edit mode to insert rather than overwrite.
- keyword
-
Same as -k.
- markdirs
-
Appends a / (slash) to all directory names that are a result of file name
substitution.
msdos
Same as -M.
- noclobber
-
Prevents redirection > from truncating existing files. A vertical bar
must follow the redirection symbol (>|) to truncate a file when this
option is turned on.
- noexec
-
Same as -n.
- noglob
-
Same as -f.
- nounset
-
Same as -u.
- os2
-
Tells the shell that the underlying operating system is OS/2.
- privileged
-
Same as -p.
- realpipes
-
Under OS/2, the shell will use OS/2 pipes and not temporary
files to handle pipelines. See LIMITATIONS.
- trackall
-
Same as -h.
- verbose
-
Same as -v.
- verify
-
Same as -V.
- vi
-
Select vi-like command line editing mode.
- winnt
-
Tells the shell that the underlying operating system is MS Windows NT.
- xtrace
-
Same as -x.
- -p
-
Not supported.
- -t
-
Exit after reading and executing one command.
- -u
-
Treat unset variables as an error when substituting.
- -v
-
Print shell input lines as they are read.
- -w
-
Disable shell warning messages.
- -x
-
Print commands and their arguments as they are executed.
- -M
-
For those variables marked as msdos variables, the values are
exported to child processes with the slashes replaced by \s. Most
MS-DOS utilities do not care if a file name contains a slash or \
as a directory separator. However, some like the linker require
\s in the value of the LIB variable.
- -V
-
Enable the File write verification option in the operation system (see
VERIFY [ ON | OFF ] under COMMAND.COM or
CMD.EXE).
- --
-
Do not change any of the flags; useful in setting $1 to -.
Using + rather than - causes these flags to be turned off. These
flags can also be used upon invocation of the shell. The current set of flags
may be found in $-. The remaining arguments are positional parameters
and are assigned, in order, to $1, $2, .... If no arguments
are given the values of all names are printed.
- shift [ n ]
-
The positional parameters from $n+1 ... are renamed $1 .... If
n is not given, it is assumed to be 1.
-
-
start [ -dfWPFibCISxhH ] [ -c [ vilsna ]] [ -t title ] [ -e string ] [ -X directory ] [ args.. ]
- start -O [ dos | pm ] [ -hHfWPFxibID ] [ -c [ vilsna ]] [ -t title ] [ -e string ]
-
- start -A sessionId
-
This command (which is only available under OS/2) has three forms.
The first form starts an OS/2 (or MS-DOS under OS/2 2.x)
program in a new session. If no program and arguments
parameters are entered, the shell is started unless the -C option has been
used to select the OS/2 command processor. Also see
DosStartSession(2).
The second form allows you to display and/or modify the default
parameters used to DosStartSession(2) when the shell automatically
starts a new session (ie when you attempt to run an OS/2 PM or
MS-DOS program). A different set of parameters are used depending on
the program type and you can modify either the OS/2 PM via -O pm,
or MS-DOS via -O dos parameters. To use this form, the -O
switch must be the first option on the command line.
The third form allows you to select the session sessionID.
The arguments changes the way the shell starts the session as follows:
-
- -d
-
Normally, command are started by invoking the shell in the new session. This
option invokes the command directly.
- -S
-
Invoke the shell to started the command in the new session.
- -f
-
The program becomes the foreground session. If this parameter is not specified,
the program becomes a background session.
- -b
-
The program becomes the background session.
- -i
-
The new session will inherit the original environment of the shell instead of
the current environment.
- -I
-
The new session will independent of the current process. Normally, the
session is a child session of the current process. Independent sessions are
not terminated when the shell terminates. Starting a child session prevents
any child session or process from also starting new sessions.
- -x
-
The new session will a child session of the current process.
- -t title
-
Sets the title of the new session.
- -F
-
This application is a full-screen application that must run in a separate
session independent of Presentation Manager.
- -W
-
This is an OS/2 application that runs within a Presentation Manager
window.
- -P
-
This application is started as a Presentation Manager application.
- -C
-
Use the OS/2 command processor instead of the shell.
- -e string
-
This option can be used multiple times on the command line and allows the
user to explicitly specify the environment to be passed to the new process.
When this option is used, only those environment variables set up by the
-e options are set in the new session's environment. Only one
environment variable can be assigned per -e switch. The
strings are in standard environment format (name=value).
This may of particular use under OS/2 2.x when starting MS-DOS
programs.
- -c [ vilsna ]
-
This option allows the user to configure the size of the window created for
the new session: v - visible; i - invisible; l - maximise;
s - minimise; n - no autoclose; or a - autoclose.
Multiple selections can be made on one option. Any selection removes any
inappropriate previous selections (ie. maximise removes any previous
selected minimise). Multiple -c options are not cumulative
and only take the values selected by the last -c option. The default
is window configuration is no autoclose.
- -A sessionId
-
This option cannot be used with any other option and allows the user to
switch to another session, given by sessionID, which must be a child
session of the current session.
- -X directory
-
This option allows the user to select the startup directory if the command
is to started in a new session via the shell.
- -h
-
The new session will inherit the current environment of the shell process (file
descriptors, directory, etc).
- -H
-
The new session will inherit the current session had when it started.
- -D
-
Display the start up parameters for PM or MS-DOS sessions.
- -O [ dos | pm ]
-
Select the session parameters to display or modify.
- -D
-
Display the start up parameters for PM or MS-DOS sessions.
- swap [ options ]
-
This command (which is only available on the 16-bit MS-DOS version) defines
how the shell will handle swapping itself to reduce its memory requirements
whilst other programs execute. The options are
-
- off
-
Disable swapping. The shell remains in memory whilst the child is running
and reduces the available memory by about 200K (depending on the size of
the environment and history).
- on
-
Enable all devices. The shell will swap out to either expanded or extended
memory or to disk, execute the command and then swap back in. Whilst
swapped, the shell reduces the available memory by about 3K.
- expand
-
Enable swapping to Expanded Memory. The EMS driver must exist on your
system for this to work.
- extend [ start address ]
-
Enable swapping to Extended Memory. If you have an XMS driver on your
system, the shell will use the XMS driver. Otherwise, the BIOS Interrupt
15 interface is used. The optional start address defines the based address
in the Extended Memory at which point the shell writes its swap area when
the BIOS interface is used. The default location is 0x100000.
- disk
-
Enable swapping to disk. The shell creates a temporary file and saves
itself in it. On completion, the file is deleted. This is the slowest method
of swapping.
With no options, the current swapping options are displayed.
test expr
- [ expr ]
-
Evaluate conditional expressions. Test evaluates the expression
expr and, if its value is true, returns a zero (true) exit status;
otherwise, a non-zero (false) exit status is returned; test also returns
a non-zero exit status if there are no arguments. The primitives are the
same as for the [[ expression ]] command, except
that -a and -o are not primitives, but are used to combine
operators (see test (1)). -a is the binary and operator and
-o is the binary or operator.
Notice that all the operators and flags are separate arguments to test.
Notice also that parentheses are meaningful to the shell and, therefore,
must be escaped.
- trap [ -l ] arg ] [ SignalNumber ] ...
-
The command arg is to be read and executed when the shell receives
signal(s) SignalNumber. (Note that arg is scanned once when the
trap is set and once when the trap is taken.) Trap commands are executed in
order of signal number. Any attempt to set a trap on a signal that was ignored
on entry to the current shell is ineffective.
If arg is absent all trap(s) SignalNumber are reset to their
original values. If arg is the null string this signal is ignored by
the shell and by the commands it invokes.
A potential point of confusion is that UNIX signal numbers are different
from MS-DOS and OS/2 signal numbers. MS-DOS and OS/2
signal numbers sometimes appear to differ between compilers. If a numeric
value is used, it is assumed to be a UNIX signal number and this is
mapped to the appropriate MS-DOS/OS/2 signal number. If there is
no mapping, a warning message is displayed.
If the signal number is a signal name, it is translated into the
appropriate MS-DOS/OS/2 signal number. The list of valid signal
names is displayed using the -l flag.
If SignalNumber is DEBUG then arg will be executed
after each command. If SignalNumber is ERR, arg will be
executed whenever a command has a non-zero exit code.
If SignalNumber is 0 or EXIT and the trap statement is executed
inside the body of a function, the command arg is executed after the
function completes. If SignalNumber is 0 or EXIT for a trap set
outside any function, the command arg is executed on exit from the shell.
The trap command with no arguments prints a list of commands associated
with each signal number.
- true
-
No effect; the command does nothing. A zero exit code is returned.
- typeset [ -HLRZfilprtux[n] [ name[ =value ] ] ... ]
-
When invoked inside a function, a new instance of the parameter name is created.
The parameter value and type are restored when the function completes. The
following list of attributes may be specified:
-
- -H
-
This flag provides UNIX to host-name file mapping on non-UNIX
machines (see msdos command).
- -L
-
Left justify and remove leading blanks from value. If n is non-zero
it defines the width of the field, otherwise it is determined by the width of
the value of first assignment. When the parameter is assigned to, it is
filled on the right with blanks or truncated, if necessary, to fit into the
field. Leading zeros are removed if the -Z flag is also set. The
-R flag is turned off.
- -R
-
Right justify and fill with leading blanks. If n is non-zero, it defines
the width of the field, otherwise it is determined by the width of the value of
first assignment. The field is left filled with blanks or truncated from the
end if the parameter is reassigned. The -L flag is turned off.
- -Z
-
Right justify and fill with leading zeros if the first non-blank character is
a digit and the -L flag has not been set. If n is non-zero, it
defines the width of the field, otherwise it is determined by the width of
the value of first assignment.
- -f
-
The names refer to function names rather than parameter names. No assignments
can be made and the only other valid flags are -t, which turns on
execution tracing for this function and -x, to allow the function to
remain in effect across shell procedures executed in the same process
environment.
- -i
-
Parameter is an integer. This makes arithmetic faster. If n is non-zero
it defines the output arithmetic base, otherwise the first assignment
determines the output base.
- -l
-
All upper-case characters converted to lower-case. The upper-case flag,
-u is turned off.
- -p
-
The output of this command, if any, is written onto the two-way pipe. This
option has no effect in the Shell.
- -r
-
The given names are marked readonly and these names cannot be changed by
subsequent assignment.
- -t
-
Tags the named parameters. Tags are user definable and have no special meaning
to the shell.
- -u
-
All lower-case characters are converted to upper-case characters. The
lower-case flag, -l is turned off.
- -x
-
The given names are marked for automatic export to the environment of
subsequently-executed commands.
-
Using + rather than - causes these flags to be turned off. If no name arguments
are given but flags are specified, a list of names (and optionally the values)
of the parameters which have these flags set is printed. (Using + rather than -
keeps the values to be printed.) If no names and flags are given, the names
and attributes of all parameters are printed.
- umask [ nnn ]
-
The user file-creation mask is set to nnn (see umask(2)). If
nnn is omitted, the current value of the mask is printed.
- unalias name ...
-
The aliases given by the list of names are removed from the alias list.
- unfunction name ...
-
For each name, remove the corresponding function.
- unset [ -f ] name ...
-
The parameters given by the list of names are unassigned (their values
and attributes are erased). The following variables, as well as those with
a read-only attribute cannot be unset: PATH, PS1,
PS2, and IFS. If the -f flag is set, then the
names refer to function names and the functions are removed.
Unsetting LINENO, MAILCHECK, OPTARG,
OPTIND, RANDOM, SECONDS, and
_ removes their special meaning even if they are subsequently
assigned to.
- ver
-
Display the current version of the shell.
- wait [ job ]
-
This command (which is only available under OS/2) waits for the specified
job to terminate and report its status. This status becomes the return
code for the wait command. If job is not given, wait waits
for all currently active child processes to terminate. The termination status
returned is that of the last process. See Jobs for a description of
the format of a job.
-
-
whence [ -ptv ] [ name ... ]
- type [ -pt ] [ name ... ]
-
For each name specified, indicate how it would be interpreted if used as
a command name. Note that type is a shorthand for whence -v.
If the -t option is used, the shell will report the executable type
of name (MS Windows, Character-based, MS-DOS, OS/2, MS Windows NT, etc).
-
- -p
-
Does a path search for name even if the name is an alias, a function,
or a reserved word.
- -v
-
Produces a more verbose report.
Invocation
If the shell is invoked through exec(2) and the first character of
argument zero is - or the -0(zero) switch is in the invocation line,
commands are initially read from /etc/profile (the extensions .sh
or .ksh may be used) and from $HOME/profile (the extensions
.sh or .ksh may be used) if such files exist. Next, commands are
read from the file named by performing parameter substitution on the value of
the environment parameter ENV if the file exists. Thereafter,
commands are read as described below, which is also the case when the shell
is invoked as /bin/sh. The flags below are interpreted by the shell on
invocation only; Note that unless the -c or -s flag is specified,
the first 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:
- -c string
-
If the -c flag is present commands are read from string.
- -s
-
If the -s flag is present or if no arguments remain commands are read
from the standard input. Any remaining arguments specify the positional
parameters. Shell output (except for Special Commands) is written to
file descriptor 2.
- -i
-
If the -i flag is present or if the shell input and output are attached
to a terminal, this shell is interactive. In this case, the
TERMINATE signal is ignored and the INTERRUPT signal is caught
and ignored. In all cases, the QUIT signal is ignored by the shell.
- -r
-
If the -r flag is present, the shell is a restricted shell.
- -0(zero)
-
If the -0(zero) flag is present, this has the same effect as starting the
shell with the first character of argument zero as a - (see above).
- -D variable=value
-
This option allows the setting of environment variables at the start of the
shell's execution. These variables are set up after the shell has read the
current environment. The option allows the user to change the value of
variable in the environment without changing the parent's environment.
Under UNIX, this functionality is unnecessary. However, MS-DOS, OS/2 and
MS Windows NT do not provide the necessary functionality to allow the setting
of variables just for one particular program.
- -P
-
This option enables real pipes under OS/2. See LIMITATIONS.
- -R
-
If the -R flag is present, the shell is the root shell and cannot
be terminated using exit. Under MS-DOS, the system must be re-booted.
Under OS/2, the shell must be killed by an external program. In addition,
the initialisation file is not read until just before the first keyboard input.
This allows the location of the file to be changed by changing the value of
the SHELL environment variable.
- -X directory
-
If the -X flag is present, the following directory defines the
startup directory for the shell. The shell immediately changes to this
directory.
The remaining flags and arguments are described under the set command
above.
Rsh Only
Rsh 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:
-
Changing directory (see cd(1)),
Setting the value of SHELL, ENV, or $PATH,
Specifying path or command names containing /,
Redirecting output (> and >>).
The restrictions above are enforced after profile and the
ENV files are 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 (i.e.,
/usr/rbin) that can be safely invoked by rsh. Some systems also
provide a restricted editor red.
EXIT STATUS
Errors detected by the shell, such as syntax errors, cause the shell to return
a non-zero exit status. If the shell is being used non-interactively execution
of the shell file is abandoned. Otherwise, the shell returns the exit status of
the last command executed (see also the exit command above).
FILES
/etc/profile
$HOME/profile
$HOME/history.sh.
$TMP/sh*.tmp
??/sh.ini
CRITICAL ERRORS
The Shell provide a Critical Error Handler (Interrupt 24) similar to the
standard MS-DOS handler. In addition to the standard message, the handler
also displays the Extended Error Code information in hexadecimal.
LIMITATIONS
Under MS-DOS, any TSR (Terminate Stay Resident) programs must be loaded before
loading Sh as the shell will overwrite the TSR when it reloads itself
after swapping out.
The shell checks for valid DOS filenames (single dot, not at the beginning).
Invalid dots are converted to ~. A warning message is displayed if the
shell detects an invalid file name.
Under OS/2, asynchronous commands are supported to a degree. However,
this is very limited because of the nature of the forking commands under
OS/2 which does not match the UNIX model. This difference has
also meant that pipes (as in MS-DOS) are implemented as files and not
OS/2 pipes. For more details, see the source code.
However, real OS/2 pipes can be used with care for simple pipelines which
do not create sub-shells or assume that a real child shell is created
because the shell does not create child, it simulates their creating in the
same process. This is because there is no fork under OS/2. See the
set command on how to enable/disable real pipes.
SEE ALSO
cd(1),
test(1),
umask(1),
exec(2),
pipe(2),
signal(2),
umask(2),
strtol(3),
profile(4),
environ(5) in the
UNIX System Programmer Reference Manual.
COMMAND(1) and SUBST(1) in the MS-DOS Reference Guide.
CMD(1) in the OS/2 Reference Guide.
CMD(1) in the MS Windows NT Reference Guide.
DosStartSession(2) in the OS/2 Control Program Reference
Manual.
ACKNOWLEDGEMENTS
This program is based on ideas, code or parts of code developed by:
David Korn and Steve Bourne (the original ideas)
Charles Forsyth (the original source for the MINIX Shell program)
Erik Baalbergen (the code for the test function)
Paul Falstad (the code for the maths functions)
Simon J. Gerraty (the code for the new lexical analyser and the VI/EMACS
edit functions).
In addition, a very large number of people (too many to mention) who have been
involved in testing and debugging the program.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- Definitions
-
- Commands
-
- Comments
-
- Aliasing
-
- Conditional Expressions
-
- Tilde Substitution
-
- Command Substitution
-
- Parameter Substitution
-
- Alternation
-
- Arithmetic Expansion
-
- Blank Interpretation
-
- File Name Generation
-
- Quoting
-
- Arithmetic Evaluation
-
- Prompting
-
- Input/Output
-
- Environment
-
- Signals
-
- Command Re-entry
-
- History
-
- Command Line Editing
-
- In-line Editing Options
-
- Vi Editing Mode
-
- EMACS Editing Mode
-
- Initialisation File
-
- Execution
-
- Command Line Building
-
- Functions
-
- Jobs
-
- Special Commands
-
- Invocation
-
- Rsh Only
-
- EXIT STATUS
-
- FILES
-
- CRITICAL ERRORS
-
- LIMITATIONS
-
- SEE ALSO
-
- ACKNOWLEDGEMENTS
-
This document was created by
man2html,
using the manual pages.
Time: 12:12:16 GMT, February 01, 2023