-->

Previous | Table of Contents | Next

Page 34

MODIFIERS

After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a :

h Remove a trailing pathname component, leaving only the head.
r Remove a trailing suffix of the form .xxx, leaving the basename.
e Remove all but the trailing suffix.
t Remove all leading pathname components, leaving the tail.
p Print the new command but do not execute it.
q Quote the substituted words, escaping further substitutions.
x Quote the substituted words as with q, but break into words at blanks and newlines.
s/old/new/ Substitute new for the first occurrence of old in the event line. Any delimiter can be used in place of /. The final delimiter is optional if it is the last character of the event line. The delimiter may be quoted in old and new with a single backslash. If & appears in new, it is replaced by old. A single backslash will quote the &.
& Repeat the previous substitution.
g Cause changes to be applied over the entire event line. This is used in conjunction with :s (for example, :gs/old/new/) or :&. If used with :s, any delimiter can be used in place of /, and the final delimiter is optional if it is the last character of the event line.

ARITHMETIC EVALUATION

The shell allows arithmetic expressions to be evaluated, under certain circumstances. (See the let built-in command and "Arithmetic Expansion.") Evaluation is done in long integers with no check for overflow, though division by 0 is trapped and flagged as an error. The following list of operators is grouped into levels of equal-precedence operators. The levels are listed in order of decreasing precedence.

_ + Unary minus and plus
! ~ Logical and bitwise negation
* / % Multiplication, division, remainder
+ _ Addition, subtraction
<< >> Left and right bitwise shifts
<= >= <> Comparison
== != Equality and inequality
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise OR &&
Logical AND ||
Logical OR = *= /= %= += _= <<= >>=&=^=|=
Assignment

Shell variables are allowed as operands; parameter expansion is performed before the expression is evaluated. The value of a parameter is coerced to a long integer within an expression. A shell variable need not have its integer attribute turned on to be used in an expression.

Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the form [base#]n, where base is a decimal number between 2 and 36 representing the arithmetic base, and n is a number in that base. If base is omitted, then base 10 is used.

Operators are evaluated in order of precedence. Subexpressions in parentheses are evaluated first and may override the precedence rules.

Previous | Table of Contents | Next