## Zsh ###############################
* zshall all man page of zsh +--------------+ | $ man zshall | +--------------+ * conditional expressions A conditional expression is used with the [[ compound command to test attributes of files and to compare strings. Each expression can be constructed from one or more of the following unary or binary expressions: -a file true if file exists. -b file true if file exists and is a block special file. -c file true if file exists and is a character special file. -d file true if file exists and is a directory. -e file true if file exists. -f file true if file exists and is a regular file. -g file true if file exists and has its setgid bit set. -h file true if file exists and is a symbolic link. -k file true if file exists and has its sticky bit set. -n string true if length of string is non-zero. -o option true if option named option is on. option may be a single character, in which case it is a single letter option name. (See the section `Speci- fying Options'.) -p file true if file exists and is a FIFO special file (named pipe). -r file true if file exists and is readable by current process. -s file true if file exists and has size greater than zero. -t fd true if file descriptor number fd is open and associated with a terminal device. (note: fd is not optional) -u file true if file exists and has its setuid bit set. -w file true if file exists and is writable by current process. -x file true if file exists and is executable by current process. If file exists and is a directory, then the current process has permission to search in the directory. -z string true if length of string is zero. -L file true if file exists and is a symbolic link. -O file true if file exists and is owned by the effective user ID of this process. -G file true if file exists and its group matches the effective group ID of this process. -S file true if file exists and is a socket. -N file true if file exists and its access time is not newer than its modifica- tion time. file1 -nt file2 true if file1 exists and is newer than file2. file1 -ot file2 true if file1 exists and is older than file2. file1 -ef file2 true if file1 and file2 exist and refer to the same file. string = pattern string == pattern true if string matches pattern. The `==' form is the preferred one. The `=' form is for backward compatibility and should be considered obsolete. string != pattern true if string does not match pattern. string =~ regexp true if string matches the regular expression regexp. If the option RE_MATCH_PCRE is set regexp is tested as a PCRE regular expression using the zsh/pcre module, else it is tested as a POSIX extended regular expression using the zsh/regex module. Upon successful match, some variables will be updated; no variables are changed if the matching fails. If the option BASH_REMATCH is not set the scalar parameter MATCH is set to the substring that matched the pattern and the integer parameters MBEGIN and MEND to the index of the start and end, respectively, of the match in string, such that if string is contained in variable var the expression `${var[$MBEGIN,$MEND]}' is identical to `$MATCH'. The set- ting of the option KSH_ARRAYS is respected. Likewise, the array match is set to the substrings that matched parenthesised subexpressions and the arrays mbegin and mend to the indices of the start and end posi- tions, respectively, of the substrings within string. The arrays are not set if there were no parenthesised subexpresssions. For example, if the string `a short string' is matched against the regular expression `s(...)t', then (assuming the option KSH_ARRAYS is not set) MATCH, MBE- GIN and MEND are `short', 3 and 7, respectively, while match, mbegin and mend are single entry arrays containing the strings `hor', `4' and `6, respectively. If the option BASH_REMATCH is set the array BASH_REMATCH is set to the substring that matched the pattern followed by the substrings that matched parenthesised subexpressions within the pattern. string1 < string2 true if string1 comes before string2 based on ASCII value of their char- acters. string1 > string2 true if string1 comes after string2 based on ASCII value of their char- acters. exp1 -eq exp2 true if exp1 is numerically equal to exp2. exp1 -ne exp2 true if exp1 is numerically not equal to exp2. exp1 -lt exp2 true if exp1 is numerically less than exp2. exp1 -gt exp2 true if exp1 is numerically greater than exp2. exp1 -le exp2 true if exp1 is numerically less than or equal to exp2. exp1 -ge exp2 true if exp1 is numerically greater than or equal to exp2. ( exp ) true if exp is true. ! exp true if exp is false.^ exp1 && exp2 true if exp1 and exp2 are both true. exp1 || exp2 true if either exp1 or exp2 is true. Normal shell expansion is performed on the file, string and pattern arguments, but the result of each expansion is constrained to be a single word, similar to the effect of double quotes. File generation is not performed on any form of argument to conditions. However, pattern metacharacters are active for the pattern arguments; the patterns are the same as those used for filename genera- tion, see zshexpn(1), but there is no special behaviour of `/' nor initial dots, and no glob qualifiers are allowed. In each of the above expressions, if file is of the form `/dev/fd/n', where n is an integer, then the test applied to the open file whose descriptor number is n, even if the underlying system does not support the /dev/fd directory. In the forms which do numeric comparison, the expressions exp undergo arith- metic expansion as if they were enclosed in $((...)). For example, the following: [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists. tests if either file foo or file bar exists, and if so, if the value of the parameter report begins with `y'; if the complete condition is true, the mes- sage `File exists.' is printed. * Globbing Flags There are various flags which affect any text to their right up to the end of the enclosing group or to the end of the pattern; they require the EXTENDED_GLOB option. All take the form (#X) where X may have one of the fol- lowing forms: i Case insensitive: upper or lower case characters in the pattern match upper or lower case characters. l Lower case characters in the pattern match upper or lower case charac- ters; upper case characters in the pattern still only match upper case characters. I Case sensitive: locally negates the effect of i or l from that point on. b Activate backreferences for parenthesised groups in the pattern; this does not work in filename generation. When a pattern with a set of active parentheses is matched, the strings matched by the groups are stored in the array $match, the indices of the beginning of the matched parentheses in the array $mbegin, and the indices of the end in the array $mend, with the first element of each array corresponding to the first parenthesised group, and so on. These arrays are not otherwise special to the shell. The indices use the same convention as does parameter substitution, so that elements of $mend and $mbegin may be used in subscripts; the KSH_ARRAYS option is respected. Sets of glob- bing flags are not considered parenthesised groups; only the first nine active parentheses can be referenced. For example, foo="a string with a message" if [[ $foo = (a|an)' '(#b)(*)' '* ]]; then print ${foo[$mbegin[1],$mend[1]]} fi prints `string with a'. Note that the first parenthesis is before the (#b) and does not create a backreference. Backreferences work with all forms of pattern matching other than file- name generation, but note that when performing matches on an entire array, such as ${array#pattern}, or a global substitution, such as ${param//pat/repl}, only the data for the last match remains available. In the case of global replacements this may still be useful. See the example for the m flag below. The numbering of backreferences strictly follows the order of the open- ing parentheses from left to right in the pattern string, although sets of parentheses may be nested. There are special rules for parentheses followed by `#' or `##'. Only the last match of the parenthesis is remembered: for example, in `[[ abab = (#b)([ab])# ]]', only the final `b' is stored in match[1]. Thus extra parentheses may be necessary to match the complete segment: for example, use `X((ab|cd)#)Y' to match a whole string of either `ab' or `cd' between `X' and `Y', using the value of $match[1] rather than $match[2]. If the match fails none of the parameters is altered, so in some cases it may be necessary to initialise them beforehand. If some of the back- references fail to match -- which happens if they are in an alternate branch which fails to match, or if they are followed by # and matched zero times -- then the matched string is set to the empty string, and the start and end indices are set to -1. Pattern matching with backreferences is slightly slower than without. B Deactivate backreferences, negating the effect of the b flag from that point on. cN,M The flag (#cN,M) can be used anywhere that the # or ## operators can be used; it cannot be combined with other globbing flags and a bad pattern error occurs if it is misplaced. It is equivalent to the form {N,M} in regular expressions. The previous character or group is required to match between N and M times, inclusive. The form (#cN) requires exactly N matches; (#c,M) is equivalent to specifying N as 0; (#cN,) specifies that there is no maximum limit on the number of matches. m Set references to the match data for the entire string matched; this is similar to backreferencing and does not work in filename generation. The flag must be in effect at the end of the pattern, i.e. not local to a group. The parameters $MATCH, $MBEGIN and $MEND will be set to the string matched and to the indices of the beginning and end of the string, respectively. This is most useful in parameter substitutions, as otherwise the string matched is obvious. For example, arr=(veldt jynx grimps waqf zho buck) print ${arr//(#m)[aeiou]/${(U)MATCH}} forces all the matches (i.e. all vowels) into uppercase, printing `vEldt jynx grImps wAqf zhO bUck'. Unlike backreferences, there is no speed penalty for using match refer- ences, other than the extra substitutions required for the replacement strings in cases such as the example shown. M Deactivate the m flag, hence no references to match data will be cre- ated. anum Approximate matching: num errors are allowed in the string matched by the pattern. The rules for this are described in the next subsection. s, e Unlike the other flags, these have only a local effect, and each must appear on its own: `(#s)' and `(#e)' are the only valid forms. The `(#s)' flag succeeds only at the start of the test string, and the `(#e)' flag succeeds only at the end of the test string; they correspond to `^' and `$' in standard regular expressions. They are useful for matching path segments in patterns other than those in filename genera- tion (where path segments are in any case treated separately). For example, `*((#s)|/)test((#e)|/)*' matches a path segment `test' in any of the following strings: test, test/at/start, at/end/test, in/test/mid- dle. Another use is in parameter substitution; for example `${array/(#s)A*Z(#e)}' will remove only elements of an array which match the complete pattern `A*Z'. There are other ways of performing many operations of this type, however the combination of the substitution operations `/' and `//' with the `(#s)' and `(#e)' flags provides a sin- gle simple and memorable method. Note that assertions of the form `(^(#s))' also work, i.e. match any- where except at the start of the string, although this actually means `anything except a zero-length portion at the start of the string'; you need to use `(""~(#s))' to match a zero-length portion of the string not at the start. q A `q' and everything up to the closing parenthesis of the globbing flags are ignored by the pattern matching code. This is intended to support the use of glob qualifiers, see below. The result is that the pattern `(#b)(*).c(#q.)' can be used both for globbing and for matching against a string. In the former case, the `(#q.)' will be treated as a glob qualifier and the `(#b)' will not be useful, while in the latter case the `(#b)' is useful for backreferences and the `(#q.)' will be ignored. Note that colon modifiers in the glob qualifiers are also not applied in ordinary pattern matching. u Respect the current locale in determining the presence of multibyte characters in a pattern, provided the shell was compiled with MULTI- BYTE_SUPPORT. This overrides the MULTIBYTE option; the default behav- iour is taken from the option. Compare U. (Mnemonic: typically multi- byte characters are from Unicode in the UTF-8 encoding, although any extension of ASCII supported by the system library may be used.) U All characters are considered to be a single byte long. The opposite of u. This overrides the MULTIBYTE option. For example, the test string fooxx can be matched by the pattern (#i)FOOXX, but not by (#l)FOOXX, (#i)FOO(#I)XX or ((#i)FOOX)X. The string (#ia2)readme speci- fies case-insensitive matching of readme with up to two errors. When using the ksh syntax for grouping both KSH_GLOB and EXTENDED_GLOB must be set and the left parenthesis should be preceded by @. Note also that the flags do not affect letters inside [...] groups, in other words (#i)[a-z] still matches only lowercase letters. Finally, note that when examining whole paths case-insensitively every directory must be searched for all files which match, so that a pattern of the form (#i)/foo/bar/... is potentially slow. * Glob Qualifiers Patterns used for filename generation may 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. If the option BARE_GLOB_QUAL is set, then a trailing set of parentheses con- taining no `|' or `(' characters (or `~' if it is special) is taken as a set of glob qualifiers. A glob subexpression that would normally be taken as glob qualifiers, for example `(^x)', can be forced to be treated as part of the glob pattern by doubling the parentheses, in this case producing `((^x))'. If the option EXTENDED_GLOB is set, a different syntax for glob qualifiers is available, namely `(#qx)' where x is any of the same glob qualifiers used in the other format. The qualifiers must still appear at the end of the pattern. However, with this syntax multiple glob qualifiers may be chained together. They are treated as a logical AND of the individual sets of flags. Also, as the syntax is unambiguous, the expression will be treated as glob qualifiers just as long any parentheses contained within it are balanced; appearance of `|', `(' or `~' does not negate the effect. Note that qualifiers will be recognised in this form even if a bare glob qualifier exists at the end of the pattern, for example `*(#q*)(.)' will recognise executable regular files if both options are set; however, mixed syntax should probably be avoided for the sake of clarity. A qualifier may be any one of the following: / directories F `full' (i.e. non-empty) directories. Note that the opposite sense (^F) expands to empty directories and all non-directories. Use (/^F) for empty directories. . plain files @ symbolic links = sockets p named pipes (FIFOs) * executable plain files (0100) % device files (character or block special) %b block special files %c character special files r owner-readable files (0400) w owner-writable files (0200) x owner-executable files (0100) A group-readable files (0040) I group-writable files (0020) E group-executable files (0010) R world-readable files (0004) W world-writable files (0002) X world-executable files (0001) s setuid files (04000) S setgid files (02000) t files with the sticky bit (01000) fspec files with access rights matching spec. This spec may be a octal number optionally preceded by a `=', a `+', or a `-'. If none of these charac- ters is given, the behavior is the same as for `='. The octal number describes the mode bits to be expected, if combined with a `=', the value given must match the file-modes exactly, with a `+', at least the bits in the given number must be set in the file-modes, and with a `-', the bits in the number must not be set. Giving a `?' instead of a octal digit anywhere in the number ensures that the corresponding bits in the file-modes are not checked, this is only useful in combination with `='. If the qualifier `f' is followed by any other character anything up to the next matching character (`[', `{', and `<' match `]', `}', and `>' respectively, any other character matches itself) is taken as a list of comma-separated sub-specs. Each sub-spec may be either an octal number as described above or a list of any of the characters `u', `g', `o', and `a', followed by a `=', a `+', or a `-', followed by a list of any of the characters `r', `w', `x', `s', and `t', or an octal digit. The first list of characters specify which access rights are to be checked. If a `u' is given, those for the owner of the file are used, if a `g' is given, those of the group are checked, a `o' means to test those of other users, and the `a' says to test all three groups. The `=', `+', and `-' again says how the modes are to be checked and have the same meaning as described for the first form above. The second list of char- acters finally says which access rights are to be expected: `r' for read access, `w' for write access, `x' for the right to execute the file (or to search a directory), `s' for the setuid and setgid bits, and `t' for the sticky bit. Thus, `*(f70?)' gives the files for which the owner has read, write, and execute permission, and for which other group members have no rights, independent of the permissions for other users. The pattern `*(f-100)' gives all files for which the owner does not have execute permission, and `*(f:gu+w,o-rx:)' gives the files for which the owner and the other members of the group have at least write permission, and for which other users don't have read or execute permission. estring +cmd The string will be executed as shell code. The filename will be included in the list if and only if the code returns a zero status (usu- ally the status of the last command). In the first form, the first character after the `e' will be used as a separator and anything up to the next matching separator will be taken as the string; `[', `{', and `<' match `]', `}', and `>', respectively, while any other character matches itself. Note that expansions must be quoted in the string to prevent them from being expanded before globbing is done. string is then executed as shell code. The string globqual is appended to the array zsh_eval_context the duration of execution. During the execution of string the filename currently being tested is available in the parameter REPLY; the parameter may be altered to a string to be inserted into the list instead of the original filename. In addition, the parameter reply may be set to an array or a string, which overrides the value of REPLY. If set to an array, the latter is inserted into the command line word by word. For example, suppose a directory contains a single file `lonely'. Then the expression `*(e:'reply=(${REPLY}{1,2})':)' will cause the words `lonely1' and `lonely2' to be inserted into the command line. Note the quoting of string. The form +cmd has the same effect, but no delimiters appear around cmd. Instead, cmd is taken as the longest sequence of characters following the + that are alphanumeric or underscore. Typically cmd will be the name of a shell function that contains the appropriate test. For exam- ple, nt() { [[ $REPLY -nt $NTREF ]] } NTREF=reffile ls -l *(+nt) lists all files in the directory that have been modified more recently than reffile. ddev files on the device dev l[-|+]ct files having a link count less than ct (-), greater than ct (+), or equal to ct U files owned by the effective user ID G files owned by the effective group ID uid files owned by user ID id if that is a number. Otherwise, id specifies a user name: the character after the `u' will be taken as a separator and the string between it and the next matching separator will be taken as a user name. The starting separators `[', `{', and `<' match the final separators `]', `}', and `>', respectively; any other character matches itself. The selected files are those owned by this user. For example, `u:foo:' or `u[foo]' selects files owned by user `foo'. gid like uid but with group IDs or names a[Mwhms][-|+]n files accessed exactly n days ago. Files accessed within the last n days are selected using a negative value for n (-n). Files accessed more than n days ago are selected by a positive n value (+n). Optional unit specifiers `M', `w', `h', `m' or `s' (e.g. `ah5') cause the check to be performed with months (of 30 days), weeks, hours, minutes or sec- onds instead of days, respectively. An explicit `d' for days is also allowed. Any fractional part of the difference between the access time and the current part in the appropriate units is ignored in the comparison. For instance, `echo *(ah-5)' would echo files accessed within the last five hours, while `echo *(ah+5)' would echo files accessed at least six hours ago, as times strictly between five and six hours are treated as five hours. m[Mwhms][-|+]n like the file access qualifier, except that it uses the file modifica- tion time. c[Mwhms][-|+]n like the file access qualifier, except that it uses the file inode change time. L[+|-]n files less than n bytes (-), more than n bytes (+), or exactly n bytes in length. If this flag is directly followed by a `k' (`K'), `m' (`M'), or `p' (`P') (e.g. `Lk-50') the check is performed with kilobytes, megabytes, or blocks (of 512 bytes) instead. In this case a file is regarded as "exactly" the size if the file size rounded up to the next unit is equal to the test size. Hence `*(Lm1)' matches files from 1 byte up to 1 Megabyte inclusive. Note also that the set of files "less than" the test size only includes files that would not match the equality test; hence `*(Lm-1)' only matches files of zero size. ^ negates all qualifiers following it - toggles between making the qualifiers work on symbolic links (the default) and the files they point to M sets the MARK_DIRS option for the current pattern T appends a trailing qualifier mark to the filenames, analogous to the LIST_TYPES option, for the current pattern (overrides M) N sets the NULL_GLOB option for the current pattern D sets the GLOB_DOTS option for the current pattern n sets the NUMERIC_GLOB_SORT option for the current pattern oc specifies how the names of the files should be sorted. If c is n they are sorted by name (the default); if it is L they are sorted depending on the size (length) of the files; if l they are sorted by the number of links; if a, m, or c they are sorted by the time of the last access, modification, or inode change respectively; if d, files in subdirecto- ries appear before those in the current directory at each level of the search -- this is best combined with other criteria, for example `odon' to sort on names for files within the same directory; if N, no sorting is performed. Note that a, m, and c compare the age against the current time, hence the first name in the list is the youngest file. Also note that the modifiers ^ and - are used, so `*(^-oL)' gives a list of all files sorted by file size in descending order, following any symbolic links. Unless oN is used, multiple order specifiers may occur to resolve ties. oe and o+ are special cases; they are each followed by shell code, delimited as for the e glob qualifier and the + glob qualifier respec- tively (see above). The code is executed for each matched file with the parameter REPLY set to the name of the file on entry and globsort appended to zsh_eval_context. The code should modify the parameter REPLY in some fashion. On return, the value of the parameter is used instead of the file name as the string on which to sort. Unlike other sort operators, oe and o+ may be repeated, but note that the maximum number of sort operators of any kind that may appear in any glob expres- sion is 12. Oc like `o', but sorts in descending order; i.e. `*(^oc)' is the same as `*(Oc)' and `*(^Oc)' is the same as `*(oc)'; `Od' puts files in the cur- rent directory before those in subdirectories at each level of the search. [beg[,end]] specifies which of the matched filenames should be included in the returned list. The syntax is the same as for array subscripts. beg and the optional end may be mathematical expressions. As in parameter sub- scripting they may be negative to make them count from the last match backward. E.g.: `*(-OL[1,3])' gives a list of the names of the three largest files. Pstring The string will be prepended to each glob match as a separate word. string is delimited in the same way as arguments to the e glob qualifier described above. The qualifier can be repeated; the words are prepended separately so that the resulting command line contains the words in the same order they were given in the list of glob qualifiers. A typical use for this is to prepend an option before all occurrences of a file name; for example, the pattern `*(P:-f:)' produces the command line arguments `-f file1 -f file2 ...' 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). Some qualifiers, however, affect all matches generated, independent of the sublist in which they are given. These are the qualifiers `M', `T', `N', `D', `n', `o', `O' and the subscripts given in brackets (`[...]'). If a `:' appears in a qualifier list, the remainder of the expression in paren- thesis is interpreted as a modifier (see the section `Modifiers' in the section `History Expansion'). 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 actual filename generation is performed, although note that the presence of the parentheses causes the entire expression to be subjected to any global pattern matching options such as NULL_GLOB. 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-exe- cutable, 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. print b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/) demonstrates how colon modifiers and other qualifiers may be chained together. The ordinary qualifier `.' is applied first, then the colon modifiers in order from left to right. So if EXTENDED_GLOB is set and the base pattern matches the regular file builtin.pro, the shell will print `shmiltin.shmo'. * Parameter Expansion Flags If the opening brace is directly followed by an opening parenthesis, the string up to the matching closing parenthesis will be taken as a list of flags. In cases where repeating a flag is meaningful, the repetitions need not be consec- utive; for example, `(q%q%q)' means the same thing as the more readable `(%%qqq)'. The following flags are supported: # Evaluate the resulting words as numeric expressions and output the char- acters corresponding to the resulting integer. Note that this form is entirely distinct from use of the # without parentheses. If the MULTIBYTE option is set and the number is greater than 127 (i.e. not an ASCII character) it is treated as a Unicode character. % Expand all % escapes in the resulting words in the same way as in prompts (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)). If this flag is given twice, full prompt expansion is done on the resulting words, depending on the setting of the PROMPT_PERCENT, PROMPT_SUBST and PROMPT_BANG options. @ In double quotes, array elements are put into separate words. E.g., `"${(@)foo}"' is equivalent to `"${foo[@]}"' and `"${(@)foo[1,2]}"' is the same as `"$foo[1]" "$foo[2]"'. This is distinct from field split- ting by the the f, s or z flags, which still applies within each array element. A Create an array parameter with `${...=...}', `${...:=...}' or `${...::=...}'. If this flag is repeated (as in `AA'), create an asso- ciative array parameter. Assignment is made before sorting or padding. The name part may be a subscripted range for ordinary arrays; the word part must be converted to an array, for example by using `${(AA)=name=...}' to activate field splitting, when creating an asso- ciative array. a Sort in array index order; when combined with `O' sort in reverse array index order. Note that `a' is therefore equivalent to the default but `Oa' is useful for obtaining an array's elements in reverse order. c With ${#name}, count the total number of characters in an array, as if the elements were concatenated with spaces between them. C Capitalize the resulting words. `Words' in this case refers to sequences of alphanumeric characters separated by non-alphanumerics, not to words that result from field splitting. D Assume the string or array elements contain directories and attempt to substitute the leading part of these by names. The remainder of the path (the whole of it if the leading part was not subsituted) is then quoted so that the whole string can be used as a shell argument. This is the reverse of `~' substitution: see the section FILENAME EXPANSION below. e Perform parameter expansion, command substitution and arithmetic expan- sion on the result. Such expansions can be nested but too deep recursion may have unpredictable effects. f Split the result of the expansion at newlines. This is a shorthand for `ps:\n:'. F Join the words of arrays together using newline as a separator. This is a shorthand for `pj:\n:'. i Sort case-insensitively. May be combined with `n' or `O'. k If name refers to an associative array, substitute the keys (element names) rather than the values of the elements. Used with subscripts (including ordinary arrays), force indices or keys to be substituted even if the subscript form refers to values. However, this flag may not be combined with subscript ranges. L Convert all letters in the result to lower case. n Sort decimal integers numerically; if the first differing characters of two test strings are not digits, sorting is lexical. Integers with more initial zeroes are sorted before those with fewer or none. Hence the array `foo1 foo02 foo2 foo3 foo20 foo23' is sorted into the order shown. May be combined with `i' or `O'. o Sort the resulting words in ascending order; if this appears on its own the sorting is lexical and case-sensitive (unless the locale renders it case-insensitive). Sorting in ascending order is the default for other forms of sorting, so this is ignored if combined with `a', `i' or `n'. O Sort the resulting words in descending order; `O' without `a', `i' or `n' sorts in reverse lexical order. May be combined with `a', `i' or `n' to reverse the order of sorting. P This forces the value of the parameter name to be interpreted as a fur- ther parameter name, whose value will be used where appropriate. Note that flags set with one of the typeset family of commands (in particular case transformations) are not applied to the value of name used in this fashion. If used with a nested parameter or command substitution, the result of that will be taken as a parameter name in the same way. For example, if you have `foo=bar' and `bar=baz', the strings ${(P)foo}, ${(P)${foo}}, and ${(P)$(echo bar)} will be expanded to `baz'. q Quote characters that are special to the shell in the resulting words with backslashes; unprintable or invalid characters are quoted using the $'\NNN' form, with separate quotes for each octet. If this flag is given twice, the resulting words are quoted in single quotes and if it is given three times, the words are quoted in double quotes; in these forms no special handling of unprintable or invalid characters is attempted. If the flag is given four times, the words are quoted in single quotes preceded by a $. Note that in all three of these forms quoting is done unconditionally, even if this does not change the way the resulting string would be interpreted by the shell. If a q- is given (only a single q may appear), a minimal form of single quoting is used that only quotes the string if needed to protect special characters. Typically this form gives the most readable output. Q Remove one level of quotes from the resulting words. t Use a string describing the type of the parameter where the value of the parameter would usually appear. This string consists of keywords sepa- rated by hyphens (`-'). The first keyword in the string describes the main type, it can be one of `scalar', `array', `integer', `float' or `association'. The other keywords describe the type in more detail: local for local parameters left for left justified parameters right_blanks for right justified parameters with leading blanks right_zeros for right justified parameters with leading zeros lower for parameters whose value is converted to all lower case when it is expanded upper for parameters whose value is converted to all upper case when it is expanded readonly for readonly parameters tag for tagged parameters export for exported parameters unique for arrays which keep only the first occurrence of duplicated values hide for parameters with the `hide' flag special for special parameters defined by the shell u Expand only the first occurrence of each unique word. U Convert all letters in the result to upper case. v Used with k, substitute (as two consecutive words) both the key and the value of each associative array element. Used with subscripts, force values to be substituted even if the subscript form refers to indices or keys. V Make any special characters in the resulting words visible. w With ${#name}, count words in arrays or strings; the s flag may be used to set a word delimiter. W Similar to w with the difference that empty words between repeated delimiters are also counted. X With this flag, parsing errors occurring with the Q, e and # flags or the pattern matching forms such as `${name#pattern}' are reported. Without the flag, errors are silently ignored. z Split the result of the expansion into words using shell parsing to find the words, i.e. taking into account any quoting in the value. Comments are not treated specially but as ordinary strings, similar to interac- tive shells with the INTERACTIVE_COMMENTS option unset. Note that this is done very late, as for the `(s)' flag. So to access single words in the result, one has to use nested expansions as in `${${(z)foo}[2]}'. Likewise, to remove the quotes in the resulting words one would do: `${(Q)${(z)foo}}'. 0 Split the result of the expansion on null bytes. This is a shorthand for `ps:\0:'. The following flags (except p) are followed by one or more arguments as shown. Any character, or the matching pairs `(...)', `{...}', `[...]', or `<...>', may be used in place of a colon as delimiters, but note that when a flag takes more than one argument, a matched pair of delimiters must surround each argument. p Recognize the same escape sequences as the print builtin in string argu- ments to any of the flags described below that follow this argument. ~ Force string arguments to any of the flags below that follow within the parentheses to be treated as patterns. Compare with a ~ outside paren- theses, which forces the entire substituted string to be treated as a pattern. Hence, for example, [[ "?" = ${(~j.|.)array} ]] with the EXTENDED_GLOB option set succeeds if and only if $array contains the string `?' as an element. The argument may be repeated to toggle the behav- iour; its effect only lasts to the end of the parenthesised group. j:string: Join the words of arrays together using string as a separator. Note that this occurs before field splitting by the s:string: flag or the SH_WORD_SPLIT option. l:expr::string1::string2: Pad the resulting words on the left. Each word will be truncated if required and placed in a field expr characters wide. The arguments :string1: and :string2: are optional; neither, the first, or both may be given. Note that the same pairs of delimiters must be used for each of the three arguments. The space to the left will be filled with string1 (concatenated as often as needed) or spaces if string1 is not given. If both string1 and string2 are given, string2 is inserted once directly to the left of each word, truncated if necessary, before string1 is used to produce any remaining padding. If the MULTIBYTE option is in effect, the flag m may also be given, in which case widths will be used for the calculation of padding; otherwise individual multibyte characters are treated as occupying one unit of width. If the MULTIBYTE option is not in effect, each byte in the string is treated as occupying one unit of width. Control characters are always assumed to be one unit wide; this allows the mechanism to be used for generating repetitions of control charac- ters. m Only useful together with one of the flags l or r or with the # length operator when the MULTIBYTE option is in effect. Use the character width reported by the system in calculating how much of the string it occupies or the overall length of the string. Most printable characters have a width of one unit, however certain Asian character sets and cer- tain special effects use wider characters; combining characters have zero width. Non-printable characters are arbitrarily counted as zero width; how they would actually be displayed will vary. If the m is repeated, the character either counts zero (if it has zero width), else one. For printable character strings this has the effect of counting the number of glyphs (visibly separate characters), except for the case where combining characters themselves have non-zero width (true in certain alphabets). r:expr::string1::string2: As l, but pad the words on the right and insert string2 immediately to the right of the string to be padded. Left and right padding may be used together. In this case the strategy is to apply left padding to the first half width of each of the result- ing words, and right padding to the second half. If the string to be padded has odd width the extra padding is applied on the left. s:string: Force field splitting at the separator string. Note that a string of two or more characters means that all of them must match in sequence; this differs from the treatment of two or more characters in the IFS parameter. See also the = flag and the SH_WORD_SPLIT option. For historical reasons, the usual behaviour that empty array elements are retained inside double quotes is disabled for arrays generated by splitting; hence the following: line="one::three" print -l "${(s.:.)line}" produces two lines of output for one and three and elides the empty field. To override this behaviour, supply the "(@)" flag as well, i.e. "${(@s.:.)line}". Z:opts: As z but takes a combination of option letters between a following pair of delimiter characters. (Z+c+) causes comments to be parsed as a string and retained; any field in the resulting array beginning with an unquoted comment character is a comment. (Z+C+) causes comments to be parsed and removed. The rule for comments is standard: anything between a word starting with the third character of $HISTCHARS, default #, up to the next newline is a comment. (Z+n+) causes unquoted newlines to be treated as ordinary whitespace, else they are treated as if they are shell code delimiters and converted to semicolons. _:flags: The underscore (_) flag is reserved for future use. As of this revision of zsh, there are no valid flags; anything following an underscore, other than an empty pair of delimiters, is treated as an error, and the flag itself has no effect. The following flags are meaningful with the ${...#...} or ${...%...} forms. The S and I flags may also be used with the ${.../...} forms. S Search substrings as well as beginnings or ends; with # start from the beginning and with % start from the end of the string. With substitu- tion via ${.../...} or ${...//...}, specifies non-greedy matching, i.e. that the shortest instead of the longest match should be replaced. I:expr: Search the exprth match (where expr evaluates to a number). This only applies when searching for substrings, either with the S flag, or with ${.../...} (only the exprth match is substituted) or ${...//...} (all matches from the exprth on are substituted). The default is to take the first match. The exprth match is counted such that there is either one or zero matches from each starting position in the string, although for global substitution matches overlapping previous replacements are ignored. With the ${...%...} and ${...%%...} forms, the starting position for the match moves backwards from the end as the index increases, while with the other forms it moves forward from the start. Hence with the string which switch is the right switch for Ipswich? substitutions of the form ${(SI:N:)string#w*ch} as N increases from 1 will match and remove `which', `witch', `witch' and `wich'; the form using `##' will match and remove `which switch is the right switch for Ipswich', `witch is the right switch for Ipswich', `witch for Ipswich' and `wich'. The form using `%' will remove the same matches as for `#', but in reverse order, and the form using `%%' will remove the same matches as for `##' in reverse order. B Include the index of the beginning of the match in the result. E Include the index of the end of the match in the result. M Include the matched portion in the result. N Include the length of the match in the result. R Include the unmatched portion in the result (the Rest). * error at complementation (Tab key) delete ~/.zcompdump and restart zsh