 |
» |
|
|
 |
This section covers the following topics: New Default sh |  |
At 10.0, the POSIX shell sh-posix(1) replaced the Bourne shell
as the default shell. The POSIX shell now resides in /usr/bin/sh. The POSIX shell is a superset of the Bourne shell, so your sh
scripts in most cases will not need to be modified to take account of
the change. But see “Bourne Shell” for exceptions
and more information. The Bourne shell is also delivered as part of 10.x,
as /usr/old/bin/sh, so you can continue to use it if you
prefer. sh-posix will not replace the Korn shell,
but it was the standard HP-UX shell as of 10.0, and Korn shell users as
well as Bourne shell users are encouraged to migrate to it. See “Differences between the Bourne and POSIX Shells” and “Differences between the Korn and POSIX Shells”. POSIX Shell |  |
If you are root, your login shell is /sbin/sh or /usr/bin/sh,
and HISTFILE is not set in /.profile, logging is turned off.
That is, no history file is created. With logging turned off, non-interactive application
performance is improved. This is especially true for applications
with multiple processes that access the same history file. However, be aware that when logging is turned off, the following occurs: History-dependent functions, such as the history command, and
command editing using vi and emacs will not work. Active job names will be unknown on the jobs command. Some scripts might not work as expected.
If you need the history functionality and compatibility, set
the HISTFILE variable in /.profile. For 10.0: The OSF POSIX shell was ported into HP-UX 10.0 as sh-posix(1). Replaces Bourne shell:
Delivered as /usr/bin/sh. Directory /bin/posix and file /bin/posix/sh eliminated.
Now conforms to XPG4 specifications. Three new or changed commands: hash, type, export. Position of reserved file descriptors changed.
New Commands and Options: "hash" becomes a shell built-in command with the addition of -r.
New built-in command type.
export -p will be fully implemented.
Reserved File Descriptors: The reserved file descriptors 10 and 14-20 have been moved to the
maximum side of the array of available file descriptors. This should
not affect current users. Bourne Shell |  |
The Bourne shell was replaced in 10.0 by the POSIX shell,
known from 10.0 on as sh(1). The Bourne shell will not be
enhanced in the future. HP strongly encourages Bourne shell users to switch to the POSIX
shell. But for those who cannot do without it, the Bourne shell is
available on 10.x as /usr/old/bin/sh; these users can change their
PATH variable to include /usr/old/bin before their regular
path. Differences between the Bourne and POSIX ShellsAlthough the POSIX shell is a superset of the Bourne shell and contains
all the Bourne shell's syntactic constructs, Bourne shell users will
notice a few changes, including the following. Positional parameters. When a function call returns, the POSIX shell restores the
positional parameter list. This does not happen in the Bourne shell,
where the positional parameters are global to the functions. For example, if a shift operation is performed within a function
invoked by the POSIX shell, its effect will not be felt after the
function returns. Errors in functions. These abort the function but not the script.
Lookup order. Function lookup is done before the built-in commands.
Error messages. Some error messages output by the POSIX shell are different
from Bourne shell messages.
LC_TYPE, LANG Changing the value of LC_CTYPE or LANG after the shell has
started will not affect the lexical processing of shell commands in
the current shell execution environment or its subshells. IFS The shell treats each character of IFS as a delimiter. If the value of IFS is or if it is unset, then: Any sequence of those characters at the beginning or end of the
input is ignored. Any sequence of those characters within the input delimits a field.
(For example,
<newline> <space><tab>foo<tab><tab>bar<space>
|
results in two fields, foo and bar.)
If the value of IFS is null, no field-splitting occurs.
Otherwise the following rules are applied in sequence, the term
IFS white space meaning any sequence of white-space characters that are
in the IFS value (for example if IFS contains
then any sequence of space and tab characters constitutes IFS white
space).IFS white space at the beginning and end of input is ignored.
Each occurrence in the input of an IFS character that is not
IFS white space, along with any adjacent IFS white space,
delimits a field.
Non-zero-length IFS white space delimits a field.
select This command does not exist in the Bourne shell.
POSIX Shell Features New to Bourne Shell UsersNew capabilities that users switching from the Bourne shell will find include: New built-in commands. Examples: whence, alias, fg, bg, jobs, fc, getopts, kill, let, unalias.
read, print These have a -p option for co-processes. New operators. Examples:
[[..]], ((...)), >|, and |&
|
! Any command preceded by a "!" returns the logical negation of the
exit status of the command. Aliases. Aliases can be used to re-define special built-in commands. Aliases
can be created, listed and exported. New parameter substitutions. In addition to the substitutions allowed in the Bourne shell, substitutions
can be performed with the following:
${name#pattern}
${name##pattern}
${name%pattern}
${name%%pattern}
|
One-dimensional array facility. An element of an array is referenced by a subscript. set -A can be
used to assign values to an array. Tilde substitution. Tilde substitution can be performed. Parameters. In addition to parameters such as #, -, ?, $ that are set
automatically in the Bourne shell, the following parameters are set by
the POSIX shell: ERRNO, LINENO, OLDPWD, OPTIND, OPTERR,OPTARG,
PWD, PPID, REPLY, RANDOM SECONDS. Similarly, in addition to the parameters such as IFS and
CDPATH that are used by the Bourne shell, the following parameters
are used by the POSIX shell: EDITOR, ENV, FCEDIT, VISUAL, PS3, PS4,
HISTFILE, HISTSIZE. Positional parameters. Positional parameters are not limited to 9 as in the Bourne shell. Integer arithmetic. Integer arithmetic can be performed using the let command.
Or you can use the following construct: New input/output operators. These include: Single-step assignment. Values can be assigned in a single step using readonly and
export (for example export LANG=french) instead of the two
steps needed in the Bourne shell. Symbolic names. Symbolic names for signals and traps can be used. Environment variables automatically inherited. An environment variable is passed to the child process even if it is
not exported. for, while, until for, while, and until loops are executed in the current process
environment. Assignments made within loops remain effective even
after the loop completes. Job control. Job control capabilities allow the user to suspend, resume, and control
processes executing in the background. Command-line editing. You can do command-line editing with vi or emacs editing commands. History. You can use a history file to list and edit command lines.
Korn Shell |  |
The Korn shell continues to be supported on 10.x as ksh(1),
although the POSIX shell
is now the standard HP-UX shell, and HP encourages Korn shell users to
switch to it. Changes at 10.0: The reserved file descriptors 10 and 14 through 20 have been moved
to the maximum side of the array of available file descriptors. This
is a bug fix and should have no impact on current users. Differences between the Korn and POSIX ShellsAlthough the POSIX shell is based on the Korn shell, there are several
differences between them. The following is a summary of POSIX shell features that do not exist
in the Korn shell, or are implemented differently. ! command(s) Negates the exit status of the command(s) just executed. command [arg ...] Treats arg as a command, but disables function lookup on arg. export -p Writes to the standard output the names and values of all exported
variables, using quotes so that they can be re-input to the
shell as commands that export the same variables in the same way. getopts optstring name [ arg ... ] name contains ? when end of options is found. hash [external commands/programs] or hash -r The hash command adds external command locations to its list
of remembered locations. When no arguments are specified, it
reports on the contents of the list. The -r option removes the locations of all previously remembered
external commands. kill -l Lists signal names. kill -L Lists signal numbers and names. Produces the same output as kill -l in
the Korn shell.
readonly -p Writes to the standard output the names and values of all read-only
variables, using quotes so that they can be re-input to the shell to
set the same attributes to the same values. set + Lists the names of all shell variables without their values. set -C "Noclobber." Can also be set (with -C) when the shell is invoked. test -e file or True if file exists. type Indicates how each argument would be interpreted if used as a command name. umask -S Prints the current value of the mask in symbolic format. unalias -a Removes all the alias definitions from the current shell execution
environment. unset -v names "Unassigns" names (erases their values and attributes). If the
-v option is used, names refer to variable names. Unsetting ERRNO, LINENO, MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS,
TMOUT and _ removes their special meaning even if they are
subsequently assigned to. whence -p name Output is different from ksh. The -p option does a path search for name even if
name is an alias, a function, or a reserved word. IFS See “Differences between the Bourne and POSIX Shells”
earlier in this chapter
for a description of IFS in sh-posix. OPTERR New sh-posix parameter. Lookup order: sh-posix: alias function built-in $PATH ksh: alias built-in function $PATH
-c If sh-posix is invoked with -c, a process will be spawned for
it:
$ /usr/bin/sh -c "ps -f"
UID PID PPID C STIME TTY TIME COMMAND
usera 511 510 3 16:15:46 ttyp8 0:00 ps -f
usera 501 500 0 16:15:36 ttyp8 0:00 -ksh
usera 510 501 1 16:15:45 ttyp8 0:00 /usr/bin/sh -c ps -f
|
Signals sh-posix has the following signals:
0) NULL
6) ABRT (IOT for ksh)
|
Tilde expansion sh-posix provides tilde expansion on the fly for the following
parameter substitutions:
${parameter:-word}
${parameter:+word}
${parameter:=word}
${parameter:?word}
|
For example, if ~ is /users/usera:
$ a=${strings:-~}
a --> /users/usera (sh-posix)
a --> ~ (ksh)
|
Exit values for failed exec. sh-posix exits with: 126 for failed exec with ENOEXEC 127 for failed exec with EACCESS
Positional parameter 0 When executing a function, sh-posix leaves positional parameter 0
unchanged. ksh sets this parameter to the function name.
Features in ksh that are not in sh-posix: Keyword time Does not exist in sh-posix.
_ Is not a special variable in sh-posix, so no special processing is done.
|