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 |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access