| ★ wanayoo — archive 1999 http://nodevice.com/sections/ManIndex/man1978.html | Nouvelle recherche | Portail wanayoo |
| Previous Next Man Index | Sections: 0 1 2 3 4 5 6 7 8 N |
Exansion is done in the above specified order in five steps. The first is History expansion which is only performed in interactive shells. The next step is alias expansion which is done right before the command line is parsed. They are followed by process substitution, parameter expansion, command substitution, arithmetic expansion and brace expansion which are preformed in one step in left-to-right fashion. After these expansions, all unquoted occurrences of the characters \e, ' , and " are removed and the result is subjected to filename expansion followed by filename generation.
If the SH_FILE_EXPANSION option is set, the order of expansion is modified for compatibility with sh and ksh. Filename expansion is performed immediately after alias substitution preceding the set of five substitutions mentioned above.
A ~ by itself is replaced by the value of the HOME parameter. A ~ followed by a + or a - is replaced by the value of PWD or OLDPWD, respectively.
A ~ followed by a number is replaced by the directory at that position in the directory stack. ~0 is equivalent to ~+, and ~1 is the top of the stack. ~+ followed by a number is replaced by the directory at that position in the directory stack. ~+0 is equivalent to ~+, and ~+1 is the top of the stack. ~- followed by a number is replaced by the directory that many positions from the bottom of the stack. ~-0 is the bottom of the stack. The PUSHD_MINUS option exchanges the effects of ~+ and ~- where they are followed by a number.
A ~ followed by anything not already covered is looked up as a named directory, and replaced by the value of that named directory if found. Named directories are typically home directories for users on the system. They may also be defined if the text after the ~ is the name of a string shell parameter whose value begins with a /. It is also possible to define directory names using the `-d' option to the hash builtin.
In certain circumstances (in prompts, for instance), when the shell prints a path, the path is checked to see if it has a named directory as its prefix. If so, then the prefix portion is replaced with a ~ followed by the name of the directory. The shortest way of referring to the directory is used, with ties broken in favour of using a named directory, except when the directory is /.
If a word begins with an unquoted = and the EQUALS option is set, the remainder of the word is taken as the name of a command or alias. If a command exists by that name, the word is replaced by the full pathname of the command. If an alias exists by that name, the word is replaced with the text of the alias.
Filename expansion is performed on the right hand side of a parameter assignment, including those appearing after commands of the typeset family. In this case, the right hand side will be treated as a colon-separated list in the manner of PATH so that a ~ or an = following a : is eligible for expansion. All such behavior can be disabled by quoting the ~, the =, or the whole expression (but not simply the colon); the EQUALS option is also respected.
If the option MAGIC_EQUAL_SUBST is set, any unquoted shell argument in the form identifier=expression becomes eligible for file expansion as described in the previous paragraph. Quoting the first = also inhibits this.
paste <(cut -f1 file1) <(cut -f3 file2) | tee >(process1) >(process2) >/dev/null
cut s fields 1 and 3 from the files file1 and file2 respectively, paste s the results together, and sends it to the processes process1 and process2 . Note that the file, which is passed as an argument to the command, is a system pipe so programs that expect to lseek (2) on the file will not work. Also note that the previous example can be more compactly and efficiently written as:
paste <(cut -f1 file1) <(cut -f3 file2) > >(process1) > >(process2)
The shell uses pipes instead of FIFOs to implement the latter two process substitutions in the above example.
If = is used, then the file passed as an argument will be the name of a temporary file containing the output of the list process. This may be used instead of the < form for a program that expects to lseek(2) on the input file.
${name}
The value, if any, of the parameter name
is substituted.
The braces are required if name is followed by
a letter, digit, or underscore that is not to be interpreted
as part of its name.
If name is an array parameter, then the values of each
element of name is substituted, one element per word.
Otherwise, the expansion results in one word only; no
word splitting is done on the result.
${+name}
If name
is the name of a set parameter `1' is substituted,
otherwise `0' is substituted.
${name:-word}
If name
is set and is non-null then substitute its
value; otherwise substitute word. If name is
missing, substitute word.
${name:=word}
If name
is unset or is null then
set it to word; the value of the parameter is then
substituted.
${name::=word}
Set name
to word; the value of the parameter is then
substituted.
${name:?word}
If name
is set and is non-null, then substitute
its value; otherwise, print word and exit from the shell.
If word is omitted, then a standard message is printed.
${name:+word}
If name
is set and is non-null then substitute
word; otherwise substitute nothing.
${name#pattern}
${name##pattern}
If the pattern
matches the beginning of the value of
name, then substitute the value of name with
the matched portion deleted; otherwise, just
substitute the value of name. In the first
form, the smallest matching pattern is preferred;
in the second form, the largest matching pattern is
preferred. If name is an array and the substitution
is not quoted or the @ flag or the name[@] syntax
is used, matching is performed on each array elements separately.
${name%pattern}
${name%%pattern}
If the pattern
matches the end of the value of
name, then substitute the value of name with
the matched portion deleted; otherwise, just
substitute the value of name. In the first
form, the smallest matching pattern is preferred;
in the second form, the largest matching pattern is
preferred. If name is an array and the substitution
is not quoted or the @ flag or the name[@] syntax
is used, matching is performed on each array elements separately.
${name:#pattern}
If the pattern
matches the value of name, then substitute
the empty string; otherwise, just substitute the value of name.
If name is an array and the substitution
is not quoted or the @ flag or the name[@] syntax
is used, matching is performed on each array elements separately, and
the matched array elements are removed (use the M flag to
remove the non-matched elements).
${#spec}
If spec
is one of the above substitutions, substitute
the length in characters of the result instead of
the result itself. If spec is an array expression,
substitute the number of elements of the result.
${^spec}
Turn on the RC_EXPAND_PARAM option for the
evaluation of spec
; if the ^ is doubled, turn it off.
When this option is set, array expansions of the form
foo${xx}bar, where the parameter
xx is set to (a b c), are substituted with
fooabar foobbar foocbar instead of the default
fooa b cbar.
${=spec}
Turn on the SH_WORD_SPLIT option for the
evaluation of spec
; if the = is doubled, turn it off.
When this option is set, parameter values are split into
separate words using IFS as a delimiter
before substitution.
This is done by default in most other shells.
${~spec}
Turn on the GLOB_SUBST option for the evaluation of
spec
; if the ~ is doubled, turn it off. When this option is
set, any pattern characters resulting
from the substitution become eligible for file expansion and filename
generation.
If the colon is omitted from one of the above expressions containing a colon, then the shell only checks whether name is set or not, not whether it is null.
If a ${...} type parameter expression or a $(...) type command substitution is used in place of name above, it is substituted first and the result is used as it were the value of name.
If the opening brace is directly followed by an opening parentheses the string up to the matching closing parentheses will be taken as a list of flags. Where arguments are valid, any character, or the matching pairs `(...)', `{...}', `[...]', or `<...>', may be used in place of the colon as delimiters. The following flags are supported:
A
@
e
o
O
i
L
U
C
c
w
W
p
l:\fIexpr\fB::\fIstring1\fB::\fIstring2\fB:
r:\fIexpr\fB::\fIstring1\fB::\fIstring2\fB:
j:\fIstring\fB:
F
s:\fIstring\fB:
f
S
I:\fIexpr\fB:
M
R
B
E
N
An expression of the form {x-y}, where x and y are single characters, is expanded to every character between x and y, inclusive.
An expression of the form {n1..n2}, where n1 and n2 are integers, is expanded to every number between n1 and n2, inclusive. If either number begins with a zero, all the resulting numbers will be padded with leading zeroes to that minimum width. If the numbers are in decreasing order the resulting sequence will also be in decreasing order.
If a brace expression matches none of the above forms, it is left unchanged, unless the BRACE_CCL option is set. In that case, it is expanded to a sorted list of the individual characters between the braces, in the manner of a search set. `-' is treated specially as in a search set, but `^' or `!' as the first character is treated normally.
*
?
[...]
[^...]
[!...]
<x-y>
^x
x|y
x#
x##
Parentheses may be used for grouping. Note that the | character must be within parentheses, so that the lexical analyzer does not think it is a pipe character. Also note that "/" has a higher precedence than "^"; that is:
ls ^ foo / bar
will search directories in "." except "./foo" for a file named bar.
A pathname component of the form ( foo /)# matches a path consisting of zero or more directories matching the pattern foo. As a shorthand, **/ is equivalent to (*/)# . Thus:
ls (*/)# bar
or
ls **/ bar
does a recursive directory search for files named bar, not following symbolic links. For this you can use the form ***/ .
If used for filename generation, a pattern may contain an exclusion specifier. Such patterns are of the form pat1~pat2. This pattern will generate all files matching pat1, but which do not match pat2. For example, *.c~lex.c will match all files ending in .c, except the file lex.c. This may appear inside parentheses. Note that "~" has a higher precedence than "|", so that pat1|pat2~pat3 matches any time that pat1 matches, or if pat2 matches while pat3 does not. Note also that "/" characters are not treated specially in the exclusion specifier so that a "*" will match multiple path segments if they appear in the pattern to the left of the "~".
Patterns used for filename generation may also end in a list of qualifiers enclosed in parentheses. The qualifiers specify which filenames that otherwise match the given pattern will be inserted in the argument list. A qualifier may be any one of the following:
/
.
@
=
p
*
%
%b
%c
r
w
x
A
I
E
R
W
X
s
S
t
ddev
l[-|+]ct
U
G
uid
gid
a[Mwhm][-|+]n
m[Mwhm][-|+]n
c[Mwhm][-|+]n
L[+|-]n
^
-
M
T
N
D
More than one of these lists can be combined, separated by commas. The whole list matches if at least one of the sublists matches (they are `or'ed', the qualifiers in the sublists are `and'ed').
If a : appears in a qualifier list, the remainder of the expression in parenthesis is interpreted as a modifier (see the subsection Modifiers of the section HISTORY EXPANSION). Note that each modifier must be introduced by a separate :. Note also that the result after modification does not have to be an existing file. The name of any existing file can be followed by a modifier of the form (:..) even if no filename generation is performed.
Thus:
ls *(-/)
lists all directories and symbolic links that point to directories, and
ls *(%W)
lists all world-writable device files in the current directory, and
ls *(W,X)
lists all files in the current directory that are world-writable or world-executable, and
echo /tmp/foo*(u0^@:t)
outputs the basename of all root-owned files beginning with the string "foo" in /tmp, ignoring symlinks, and
ls *.*~(lex|parse).[ch](^D^l1)
lists all files having a link count of one whose names contain a dot (but not those starting with a dot, since GLOB_DOTS is explicitly switched off) except for lex.c, lex.h, parse.c, and parse.h.
Input lines containing history substitutions are echoed on the terminal after being expanded, but before any other substitutions take place or the command gets executed.
An event designator is a reference to a command-line entry in the history list.
!
!!
! n
! -n
! str
!? str\fR[\fP ? \fR]\fP
!#
!{ .\|.\|. }
A word designator indicates which word or words of a given command line will be included in a history reference. A ` : ' separates the event specification from the word designator. It can be omitted if the word designator begins with a ^ , $ , * , - or % . Word designators include:
0
n
^
$
%
x - y
*
x *
x -
Note that a ` % ' word designator will only work when used as !%, !:%, !? str ?:% and only when used after a !? substitution. Anything else will result in an error, although the error may not be the most obvious one.
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
r
e
t
&
g
p
q
x
l
u
f
F:\fIexpr\fB:
w
W:\fIsep\fB:
s/ l / r\fR[\fP / \fR]\fP
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\fR. 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 the entry in the zshbuiltins manual).
| Previous Next Man Index | Sections: 0 1 2 3 4 5 6 7 8 N |