HP-UX Reference (11i v2 04/09) - 1 User Commands N-Z (vol 2)

s
sh-posix(1) sh-posix(1)
Aliasing
The first word of each command is replaced by the text of an
alias,ifanalias for this word has been
defined. An
alias name consists of any number of characters excluding metacharacters, quoting char-
acters, file expansion characters, parameter and command substitution characters, and =. The replace-
ment string can contain any valid shell script, including the metacharacters listed above. The first word
of each command in the replaced text, other than any that are in the process of being replaced, will be
tested for additional aliases. If the last character of the alias value is a blank, the word following the
alias is also checked for alias substitution. Aliases can be used to redefine special commands, but cannot
be used to redefine the keywords listed in the Compound Commands subsection. Aliases can be created,
listed, and exported with the
alias command and can be removed with the
unalias command.
Exported aliases remain in effect for subshells but must be reinitialized for separate invocations of the
shell (see the Shell Invocation subsection).
Aliasing is performed when scripts are read, not while they are executed. Therefore, for it to take effect,
an
alias must be executed before the command referring to the alias is read.
Aliases are frequently used as a shorthand for full path names. An option to the aliasing facility allows
the value of the alias to be automatically set to the full path name of the corresponding command. These
aliases are called tracked aliases. The value of a tracked alias is defined the first time the identifier is
read and becomes undefined each time the
PATH variable is reset. These aliases remain tracked so that
the next reference will redefine the value. Several tracked aliases are compiled into the shell. The
-h
option of the set command converts each command name that is an identifier into a tracked alias.
The following exported aliases are compiled into the shell but can be unset or redefined:
autoload=’typeset -fu’
command=’command ’
functions=’typeset -f’
history=’fc -l’
integer=’typeset -i’
local=typeset
nohup=’nohup ’
r=’fc -e -’
stop=’kill -STOP’
suspend=’kill -STOP $$’
type=’whence -v’
Tilde Substitution
After alias substitution is performed, each word is checked to see if it begins with an unquoted tilde (
˜).
If it does, the word up to a
/ is checked to see if it matches a user name in the
/etc/passwd file. If a
match is found, the
˜ and the matched login name are replaced by the login directory of the matched
user. If no match is found, the original text is left unchanged. A ˜ alone or before a
/ 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. In addition, tilde substitution is attempted when the value of a parameter
assignment begins with a ˜.
Command Substitution
The standard output from a command enclosed in parenthesis preceded by a dollar sign (
$(...)) or a pair
of grave accents (...) can be used as part or all of a word; trailing newlines are removed. In the second
(archaic) form, the string between the accents is processed for special quoting characters before the com-
mand is executed. See the Quoting subsection. The command substitution $(cat file) can be
replaced by the equivalent but faster $(<file). Command substitution of most special commands that
do not perform input/output redirection are carried out without creating a separate process.
An arithmetic expression enclosed in double parenthesis preceded by a dollar sign (
$((...)))isreplaced
by the value of the arithmetic expression within the double parenthesis. See the Arithmetic Evaluation
subsection for a description of arithmetic expressions.
Parameter Substitution
A parameter is an identifier, one or more decimal digits, or one of the characters
!, #, $, *, -, ?, @, and
_.Anamed parameter (a parameter denoted by an identifier) has a value and zero or more attributes.
Named parameters can be assigned values and attributes with the typeset special command. Exported
parameters pass values and attributes to the environment.
Section 1856 Hewlett-Packard Company 12 HP-UX 11i Version 2: September 2004