HP-UX Reference (11i v2 03/08) - 1 User Commands N-Z (vol 2)
s
sh-posix(1) sh-posix(1)
Arithmetic Evaluation
Integer arithmetic is provided with the special command
let. Evaluations are performed using long
integer arithmetic. Constants take the form base
#
n or 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, base
10 is used.
An arithmetic expression uses the same syntax, precedence, and associativity of expression as the C
language. All the integral operators, other than
++
, --, ?:, and , are supported. Variables can be refer-
enced by name within an arithmetic expression without using the parameter substitution syntax. When a
variable is referenced, its value is evaluated as an arithmetic expression.
A variable can be typed as an integer with the
-i option of the typeset special command, as in
typeset -i
[base] name. Arithmetic evaluation is performed on the value of each assignment to a
variable with the
-i attribute. If you do not specify an arithmetic base, the first assignment to the vari-
able determines the arithmetic base. This base is used when parameter substitution occurs.
Since many of the arithmetic operators require quoting, an alternative form of the
let command is pro-
vided. For any command beginning with
((, all characters until the matching )) are treated as a quoted
expression. More precisely,
((...)) is equivalent to
let "...".
Arithmetic expressions given with
let command, ((...
)), and $((...)) will be processed according to
ISOC standard with the exception of
++,
--, ?:, and , operators.
Prompting
When used interactively, the shell prompts with the value of
PS1 before reading a command. Whenever
a newline is received and further input is needed to complete a command, the secondary prompt (the
value of
PS2) is issued.
Conditional Expressions
A conditional expression is used with the
[[ compound command to test attributes of files and to com-
pare strings. Word splitting and file name generation are not performed on the words between
[[ and
]]. (See also the test special command.) 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.
-e file True, if file exists.
-f file True, if file exists and is an ordinary 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.
-n string True, if length of string is nonzero.
-o option True, if the set option named option 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 by current process.
-s file True, if file exists and has a size greater than zero.
-t fildes True, if file descriptor number fildes is open and 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 by the current process.
-x file True, if file exists and is executable by the current process. If file exists and is
a directory, then the current process has permission to search in the directory.
-z string True, if 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.
-G file True, if file exists and its group matches the effective group ID of this process.
-S file True, if file exists and is a socket.
file1 -nt 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 exist and refer to the same file.
string = pattern True, if string matches pattern .
string != pattern True, if string does not match pattern .
HP-UX 11i Version 2: August 2003 − 17 − Hewlett-Packard Company Section 1−−815