Variable Modifiers
Except for $?
var
, $?0
, $#
var
, $%
var
,
$#
, $$
, $?
,
$!
, $_
, and $<
, the variable substitutions in the
preceding section may be followed by one of these
modifiers (when braces are used, the modifier goes inside
them):
|
Return the variable’s root (the portion before the last dot). |
|
Return the variable’s extension. |
|
Return the variable’s header (the directory portion). |
|
Return the variable’s tail (the portion after the last slash). |
|
Return all roots. |
|
Return all extensions. |
|
Return all headers. |
|
Return all tails. |
|
Quote a wordlist variable, keeping the items separate. Prevents further substitution. Useful when the variable contains filename metacharacters that should not be expanded. |
|
Quote a pattern, expanding it into a wordlist. |
Examples using pathname modifiers
The following table shows the effect of pathname modifiers
if the aa
variable is set as
follows:
set aa=(/progs/num.c /book/chap.ps)
Variable portion |
Specification |
Output result |
Normal variable |
|
/progs/num.c /book/chap.ps |
Second root |
|
/book/chap |
Second header |
|
/book |
Second tail |
|
chap.ps |
Second extension |
|
ps |
Root |
|
/progs/num /book/chap.ps |
Global root |
|
/progs/num /book/chap |
Header |
|
/progs /book/chap.ps |
Global header |
|
/progs /book |
Tail |
|
num.c /book/chap.ps |
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.