Table of Contents
Modifiers
After the optional word designator, you can add a sequence of one or
more of the following modifiers, each preceded by a :. These
modifiers also work on the result of filename and parameter
expansion.
- h
- Remove a trailing pathname component, leaving the head.
- r
-
Remove a trailing suffix of the form `.xxx', leaving the basename.
- e
- Remove all but the suffix.
- t
- Remove all leading pathname components, leaving the tail.
- &
- Repeat the previous substitution.
- g
-
Apply the change to the first occurrence of a match in each word, by
prefixing the above (for example, g&).
- p
- Print the new command but do not execute it.
- q
- Quote the substituted words, escaping further substitutions.
- x
- Like q, but break into words at each blank.
- l
- Convert the words to all lowercase.
- u
- Convert the words to all uppercase.
- f
-
Repeats the immediately (without a colon) following modifier until the
resulting word doesn't change any more. This one and the following
four only work with parameter and filename expansion.
- F:expr:
-
Like f, but repeats only n times if the expression
expr evaluates to n. Any character can be used instead
of the `:', if any of `(', `[', or `{' is used as the opening
delimiter the second one has to be `)', `]', or `}' respectively.
- w
-
Makes the immediately following modifier work on each word in the string.
- W:sep:
-
Like w but words are considered to be the parts of the string
that are separated by sep. Any character can be used instead of
the `:', opening parentheses are handled specially, see above.
- s/l/r[/]
-
Substitute r for l. Unless preceded by a g, the
substitution is done only for the first string that matches l.
The left-hand side of substitutions are not regular expressions, but
character strings. Any character can be used as the delimiter in place
of /. A backslash quotes the delimiter character. The character
&, in the right hand side, is replaced by the text from the
left-hand-side. The & can be quoted with a backslash. A null
l uses the previous string either from a l or from a
contextual scan string s from !?s. You can omit the
rightmost delimiter if a newline immediately follows r; the
rightmost ? in a context scan can similarly be omitted.
By default, a history reference with no event specification refers to
the same line as the last history reference on that command line,
unless it is the first history reference in a command. In that case, a
history reference with no event specification always refers to the
previous command. However, if the option CSH_JUNKIE_HISTORY is
set, then history reference with no event specification will
always refer to the previous command. For example, !!:1
will always refer to the first word of the previous command and
!!$ will always refer to the last word of the previous
command. And with CSH_JUNKIE_HISTORY set, then !:1 and
!$ will function in the same manner as !!:1 and
!!$, respectively. However, if CSH_JUNKIE_HISTORY is
unset, then !:1 and !$ will refer to the first and last
words respectively, of the last command referenced on the current
command line. However, if they are the first history reference on the
command line, then they refer to the previous command.
The character sequence ^foo^bar repeats the last command,
replacing the string "foo" with the string "bar".
If the shell encounters the character sequence !" in the
input, the history mechanism is temporarily disabled until the current
list is fully parsed. The !" is removed from the input,
and any subsequent ! characters have no special
significance.
A less convenient but more comprehensible form of command history
support is provided by the fc builtin (see below).
ARITHMETIC EVALUATION
An ability to perform integer arithmetic is provided with the builtin
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
(for example, `16#ff' is 255 in hexadecimal). If base is
omitted then base 10 is used. For backwards compatibility the form
`[16]ff' is also accepted.
An arithmetic expression uses nearly the same syntax, precedence, and
associativity of expressions in C. The following operators are
supported (listed in decreasing order of precedence):
- + - ! ~ ++ --
-
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement
- &
- logical AND
- ^
- logical XOR
- |
- logical OR
- * / % **
- multiplication, division, remainder, exponentiation
- + -
-
addition, subtraction
- << >>
- logical shift left, shift right
- < > <= >=
- comparison
- == !=
- equality and inequality
- &&
- boolean AND
- || ^^
- boolean OR, XOR
- ? :
- ternary operator
- = += -= *= /= %= &=
^= |= <<= >>= &&=
||= ^^= **=
- assignment
- ,
- comma operator
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, OR, and XOR operators.
An expression of the form #\x where x is any character
gives the ascii value of this character and an expression of the form
#foo gives the ascii value of the first character of the value
of the parameter foo.
Named parameters can be referenced by name within an arithmetic
expression without using the parameter substitution syntax, but if it
is an array with a subscript the leading $ is needed.
An internal integer representation of a named parameter can be
specified with the integer builtin. Arithmetic evaluation is
performed on the value of each assignment to a named parameter
declared integer in this manner.
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
"...".
Mark D. Borges