{
    "mode": "man",
    "parameter": "ZSHEXPN",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/ZSHEXPN/1/json",
    "generated": "2026-11-09T19:39:54Z",
    "sections": {
        "NAME": {
            "content": "zshexpn - zsh expansion and substitution\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The following types of expansions are performed in the indicated order in five steps:\n\nHistory Expansion\nThis is performed only in interactive shells.\n\nAlias Expansion\nAliases  are expanded immediately before the command line is parsed as explained under\nAliasing in zshmisc(1).\n\nProcess Substitution\nParameter Expansion\nCommand Substitution\nArithmetic Expansion\nBrace Expansion\nThese five are performed in left-to-right fashion.  On each argument, any of the  five\nsteps  that are needed are performed one after the other.  Hence, for example, all the\nparts of parameter expansion are completed before  command  substitution  is  started.\nAfter these expansions, all unquoted occurrences of the characters `\\',`'' and `\"' are\nremoved.\n\nFilename Expansion\nIf the SHFILEEXPANSION option is set, the order of expansion is modified for compat‐\nibility with sh and ksh.  In that case filename expansion is performed immediately af‐\nter alias expansion, preceding the set of five expansions mentioned above.\n\nFilename Generation\nThis expansion, commonly referred to as globbing, is always done last.\n\nThe following sections explain the types of expansion in detail.\n",
            "subsections": []
        },
        "HISTORY EXPANSION": {
            "content": "History expansion allows you to use words from previous command lines in the command line you\nare  typing.  This simplifies spelling corrections and the repetition of complicated commands\nor arguments.\n\nImmediately before execution, each command is saved in the history list, the size of which is\ncontrolled by the HISTSIZE parameter.  The one most recent command is always retained in  any\ncase.   Each  saved  command  in the history list is called a history event and is assigned a\nnumber, beginning with 1 (one) when the shell starts up.  The history number that you may see\nin your prompt (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)) is the number that is to  be\nassigned to the next command.\n",
            "subsections": [
                {
                    "name": "Overview",
                    "content": "A  history expansion begins with the first character of the histchars parameter, which is `!'\nby default, and may occur anywhere on the command line, including inside double  quotes  (but\nnot inside single quotes '...' or C-style quotes $'...' nor when escaped with a backslash).\n\nThe  first character is followed by an optional event designator (see the section `Event Des‐\nignators') and then an optional word designator (the section `Word Designators'); if  neither\nof these designators is present, no history expansion occurs.\n\nInput  lines  containing  history  expansions are echoed after being expanded, but before any\nother expansions take place and before the command is executed.  It  is  this  expanded  form\nthat is recorded as the history event for later references.\n\nHistory expansions do not nest.\n\nBy default, a history reference with no event designator refers to the same event as any pre‐\nceding  history reference on that command line; if it is the only history reference in a com‐\nmand, it refers to the previous command.  However, if the option CSHJUNKIEHISTORY  is  set,\nthen  every  history reference with no event specification always refers to the previous com‐\nmand.\n\nFor example, `!' is the event designator for the previous command, so `!!:1' always refers to\nthe first word of the previous command, and `!!$' always refers to the last word of the  pre‐\nvious  command.  With CSHJUNKIEHISTORY set, then `!:1' and `!$' function in the same manner\nas `!!:1' and `!!$', respectively.  Conversely, if CSHJUNKIEHISTORY is  unset,  then  `!:1'\nand `!$' refer to the first and last words, respectively, of the same event referenced by the\nnearest  other history reference preceding them on the current command line, or to the previ‐\nous command if there is no preceding reference.\n\nThe character sequence `^foo^bar'  (where  `^'  is  actually  the  second  character  of  the\nhistchars  parameter) repeats the last command, replacing the string foo with bar.  More pre‐\ncisely, the sequence `^foo^bar^' is synonymous with `!!:s^foo^bar^',  hence  other  modifiers\n(see  the  section  `Modifiers') may follow the final `^'.  In particular, `^foo^bar^:G' per‐\nforms a global substitution.\n\nIf the shell encounters the character sequence `!\"' in the input, the  history  mechanism  is\ntemporarily  disabled  until  the current list (see zshmisc(1)) is fully parsed.  The `!\"' is\nremoved from the input, and any subsequent `!' characters have no special significance.\n\nA less convenient but more comprehensible form of command history support is provided by  the\nfc builtin.\n"
                },
                {
                    "name": "Event Designators",
                    "content": "An  event designator is a reference to a command-line entry in the history list.  In the list\nbelow, remember that the initial `!' in each item may be changed to another character by set‐\nting the histchars parameter.\n\n!      Start a history expansion, except when followed by a blank, newline, `=' or  `('.   If\nfollowed  immediately  by a word designator (see the section `Word Designators'), this\nforms a history reference with no event designator (see the section `Overview').\n\n!!     Refer to the previous command.  By itself, this expansion repeats  the  previous  com‐\nmand.\n\n!n     Refer to command-line n.\n\n!-n    Refer to the current command-line minus n.\n\n!str   Refer to the most recent command starting with str.\n\n!?str[?]\nRefer  to  the  most  recent command containing str.  The trailing `?' is necessary if\nthis reference is to be followed by a modifier or followed by any text that is not  to\nbe considered part of str.\n\n!#     Refer  to the current command line typed in so far.  The line is treated as if it were\ncomplete up to and including the word before the one with the `!#' reference.\n\n!{...} Insulate a history reference from adjacent characters (if necessary).\n"
                },
                {
                    "name": "Word Designators",
                    "content": "A word designator indicates which word or words of a given command line are to be included in\na history reference.  A `:' usually separates the event specification from the word  designa‐\ntor.   It may be omitted only if the word designator begins with a `^', `$', `*', `-' or `%'.\nWord designators include:\n\n0      The first input word (command).\nn      The nth argument.\n^      The first argument.  That is, 1.\n$      The last argument.\n%      The word matched by (the most recent) ?str search.\nx-y    A range of words; x defaults to 0.\n*      All the arguments, or a null value if there are none.\nx*     Abbreviates `x-$'.\nx-     Like `x*' but omitting word $.\n\nNote that a `%' word designator works only when used in one of `!%', `!:%' or `!?str?:%', and\nonly when used after a !? expansion (possibly in an earlier command).  Anything else  results\nin an error, although the error may not be the most obvious one.\n"
                },
                {
                    "name": "Modifiers",
                    "content": "After  the  optional  word designator, you can add a sequence of one or more of the following\nmodifiers, each preceded by a `:'.  These modifiers also work on the result of filename  gen‐\neration and parameter expansion, except where noted.\n\na      Turn a file name into an absolute path:  prepends the current directory, if necessary;\nremove  `.' path segments; and remove `..' path segments and the segments that immedi‐\nately precede them.\n\nThis transformation is agnostic about what is in the filesystem, i.e. is on the  logi‐\ncal,  not  the physical directory.  It takes place in the same manner as when changing\ndirectories when neither of the options CHASEDOTS or CHASELINKS is set.   For  exam‐\nple,  `/before/here/../after'  is always transformed to `/before/after', regardless of\nwhether `/before/here' exists or what kind of object (dir, file, symlink, etc.) it is.\n\nA      Turn a file name into an absolute path as the `a' modifier does, and then pass the re‐\nsult through the realpath(3) library function to resolve symbolic links.\n\nNote: on systems that do not have a realpath(3) library function, symbolic  links  are\nnot resolved, so on those systems `a' and `A' are equivalent.\n\nNote:  foo:A and realpath(foo) are different on some inputs.  For realpath(foo) seman‐\ntics, see the `P` modifier.\n\nc      Resolve a command name into an absolute path by searching the command  path  given  by\nthe  PATH variable.  This does not work for commands containing directory parts.  Note\nalso that this does not usually work as a glob qualifier unless a  file  of  the  same\nname is found in the current directory.\n\ne      Remove  all  but the part of the filename extension following the `.'; see the defini‐\ntion of the filename extension in the description of the r modifier below.  Note  that\naccording to that definition the result will be empty if the string ends with a `.'.\n\nh [ digits ]\nRemove a trailing pathname component, shortening the path by one directory level: this\nis the `head' of the pathname.  This works like `dirname'.  If the h is followed imme‐\ndiately  (with  no spaces or other separator) by any number of decimal digits, and the\nvalue of the resulting number is non-zero, that number of leading components  is  pre‐\nserved  instead of the final component being removed.  In an absolute path the leading\n`/' is the first  component,  so,  for  example,  if  var=/my/path/to/something,  then\n${var:h3}  substitutes  /my/path.   Consecutive  `/'s are treated the same as a single\n`/'.  In parameter substitution, digits may only be  used  if  the  expression  is  in\nbraces,  so  for  example the short form substitution $var:h2 is treated as ${var:h}2,\nnot as ${var:h2}.  No restriction applies to the use of digits in history substitution\nor globbing qualifiers.  If more components are requested than are present, the entire\npath is substituted (so this does not trigger a `failed modifier' error in history ex‐\npansion).\n\nl      Convert the words to all lowercase.\n\np      Print the new command but do not execute it.  Only works with history expansion.\n\nP      Turn a file name into an absolute path, like realpath(3).  The resulting path will  be\nabsolute,  will  refer  to the same directory entry as the input filename, and none of\nits components will be symbolic links or equal to `.' or `..'.\n\nUnlike realpath(3), non-existent trailing components are permitted and preserved.\n\nq      Quote the substituted words, escaping further substitutions.  Works with  history  ex‐\npansion  and  parameter  expansion, though for parameters it is only useful if the re‐\nsulting text is to be re-evaluated such as by eval.\n\nQ      Remove one level of quotes from the substituted words.\n\nr      Remove a filename extension leaving the root name.  Strings with no filename extension\nare not altered.  A filename extension is a `.' followed by any number  of  characters\n(including  zero)  that  are  neither  `.' nor `/' and that continue to the end of the\nstring.  For example, the extension of `foo.orig.c' is `.c', and  `dir.c/foo'  has  no\nextension.\n\ns/l/r[/]\nSubstitute  r  for  l as described below.  The substitution is done only for the first\nstring that matches l.  For arrays and for filename generation, this applies  to  each\nword of the expanded text.  See below for further notes on substitutions.\n\nThe  forms  `gs/l/r' and `s/l/r/:G' perform global substitution, i.e. substitute every\noccurrence of r for l.  Note that the g or :G must  appear  in  exactly  the  position\nshown.\n\nSee further notes on this form of substitution below.\n\n&      Repeat  the  previous s substitution.  Like s, may be preceded immediately by a g.  In\nparameter expansion the & must appear inside braces, and  in  filename  generation  it\nmust be quoted with a backslash.\n\nt [ digits ]\nRemove  all  leading  pathname  components,  leaving the final component (tail).  This\nworks like `basename'.  Any trailing slashes are first removed.   Decimal  digits  are\nhandled  as  described  above for (h), but in this case that number of trailing compo‐\nnents is preserved instead of the default 1; 0 is treated the same as 1.\n\nu      Convert the words to all uppercase.\n\nx      Like q, but break into words at whitespace.  Does not work with parameter expansion.\n\nThe s/l/r/ substitution works as follows.  By default the left-hand side of substitutions are\nnot patterns, but character strings.  Any character can be used as the delimiter in place  of\n`/'.   A backslash quotes the delimiter character.  The character `&', in the right-hand-side\nr, is replaced by the text from the left-hand-side l.  The `&' can be  quoted  with  a  back‐\nslash.   A  null l uses the previous string either from the previous l or from the contextual\nscan string s from `!?s'.  You can omit the rightmost delimiter if a newline immediately fol‐\nlows r; the rightmost `?' in a context scan can similarly be omitted.  Note the  same  record\nof the last l and r is maintained across all forms of expansion.\n\nNote  that  if  a `&' is used within glob qualifiers an extra backslash is needed as a & is a\nspecial character in this case.\n\nAlso note that the order of expansions affects the interpretation of l and r.  When used in a\nhistory expansion, which occurs before any other expansions, l and r are treated  as  literal\nstrings  (except  as  explained for HISTSUBSTPATTERN below).  When used in parameter expan‐\nsion, the replacement of r into the parameter's value is done first, and then any  additional\nprocess,  parameter, command, arithmetic, or brace references are applied, which may evaluate\nthose substitutions and expansions more than once if l appears more than once in the starting\nvalue.  When used in a glob qualifier, any substitutions or expansions are performed once  at\nthe  time  the  qualifier is parsed, even before the `:s' expression itself is divided into l\nand r sides.\n\nIf the option HISTSUBSTPATTERN is set, l is treated as a pattern  of  the  usual  form  de‐\nscribed  in  the section FILENAME GENERATION below.  This can be used in all the places where\nmodifiers are available; note, however, that in globbing  qualifiers  parameter  substitution\nhas  already  taken place, so parameters in the replacement string should be quoted to ensure\nthey are replaced at the correct time.  Note also that complicated patterns used in  globbing\nqualifiers  may  need  the  extended glob qualifier notation (#q:s/.../.../) in order for the\nshell to recognize the expression as a glob qualifier.  Further, note that  bad  patterns  in\nthe substitution are not subject to the NOBADPATTERN option so will cause an error.\n\nWhen  HISTSUBSTPATTERN is set, l may start with a # to indicate that the pattern must match\nat the start of the string to be substituted, and a % may appear at the start or after  an  #\nto indicate that the pattern must match at the end of the string to be substituted.  The % or\n# may be quoted with two backslashes.\n\nFor example, the following piece of filename generation code with the EXTENDEDGLOB option:\n\nprint -r -- *.c(#q:s/#%(#b)s(*).c/'S${match[1]}.C'/)\n\ntakes  the  expansion of *.c and applies the glob qualifiers in the (#q...) expression, which\nconsists of a substitution modifier anchored to the start and end of each  word  (#%).   This\nturns  on  backreferences ((#b)), so that the parenthesised subexpression is available in the\nreplacement string as ${match[1]}.  The replacement string is quoted so that the parameter is\nnot substituted before the start of filename generation.\n\nThe following f, F, w and W modifiers work only with parameter expansion and filename genera‐\ntion.  They are listed here to provide a single point of reference for all modifiers.\n\nf      Repeats the immediately (without a colon) following modifier until the resulting  word\ndoesn't change any more.\n\nF:expr:\nLike f, but repeats only n times if the expression expr evaluates to n.  Any character\ncan  be used instead of the `:'; if `(', `[', or `{' is used as the opening delimiter,\nthe closing delimiter should be ')', `]', or `}', respectively.\n\nw      Makes the immediately following modifier work on each word in the string.\n\nW:sep: Like w but words are considered to be the parts of the string that  are  separated  by\nsep.  Any  character  can  be used instead of the `:'; opening parentheses are handled\nspecially, see above.\n"
                }
            ]
        },
        "PROCESS SUBSTITUTION": {
            "content": "Each part of a command argument that takes the form `<(list)', `>(list)' or `=(list)' is sub‐\nject to process substitution.  The expression may be preceded or followed  by  other  strings\nexcept  that,  to prevent clashes with commonly occurring strings and patterns, the last form\nmust occur at the start of a command argument, and the forms are  only  expanded  when  first\nparsing  command  or assignment arguments.  Process substitutions may be used following redi‐\nrection operators; in this case, the substitution must appear with no trailing string.\n\nNote that `<<(list)' is not a special syntax; it is equivalent to  `<  <(list)',  redirecting\nstandard  input  from the result of process substitution.  Hence all the following documenta‐\ntion applies.  The second form (with the space) is recommended for clarity.\n\nIn the case of the < or > forms, the shell runs the commands in list as a subprocess  of  the\njob executing the shell command line.  If the system supports the /dev/fd mechanism, the com‐\nmand  argument  is the name of the device file corresponding to a file descriptor; otherwise,\nif the system supports named pipes (FIFOs), the command argument will be a  named  pipe.   If\nthe  form  with  > is selected then writing on this special file will provide input for list.\nIf < is used, then the file passed as an argument will be connected to the output of the list\nprocess.  For example,\n\npaste <(cut -f1 file1) <(cut -f3 file2) |\ntee >(process1) >(process2) >/dev/null\n\ncuts fields 1 and 3 from the files file1 and file2 respectively, pastes the results together,\nand sends it to the processes process1 and process2.\n\nIf =(...) is used instead of <(...), then the file passed as an argument will be the name  of\na  temporary file containing the output of the list process.  This may be used instead of the\n< form for a program that expects to lseek (see lseek(2)) on the input file.\n\nThere is an optimisation for substitutions of the form =(<<<arg), where arg is a  single-word\nargument  to  the here-string redirection <<<.  This form produces a file name containing the\nvalue of arg after any substitutions have been performed.  This is  handled  entirely  within\nthe  current shell.  This is effectively the reverse of the special form $(<arg) which treats\narg as a file name and replaces it with the file's contents.\n\nThe = form is useful as both the /dev/fd and the named pipe  implementation  of  <(...)  have\ndrawbacks.   In  the former case, some programmes may automatically close the file descriptor\nin question before examining the file on the command line, particularly if this is  necessary\nfor  security  reasons  such as when the programme is running setuid.  In the second case, if\nthe programme does not actually open the file, the subshell attempting to read from or  write\nto the pipe will (in a typical implementation, different operating systems may have different\nbehaviour)  block  for ever and have to be killed explicitly.  In both cases, the shell actu‐\nally supplies the information using a pipe, so that programmes  that  expect  to  lseek  (see\nlseek(2)) on the file will not work.\n\nAlso  note  that the previous example can be more compactly and efficiently written (provided\nthe MULTIOS option is set) as:\n\npaste <(cut -f1 file1) <(cut -f3 file2) > >(process1) > >(process2)\n\nThe shell uses pipes instead of FIFOs to implement the latter two  process  substitutions  in\nthe above example.\n\nThere is an additional problem with >(process); when this is attached to an external command,\nthe  parent shell does not wait for process to finish and hence an immediately following com‐\nmand cannot rely on the results being complete.  The problem and solution are the same as de‐\nscribed in the section MULTIOS in zshmisc(1).  Hence in a simplified version of  the  example\nabove:\n\npaste <(cut -f1 file1) <(cut -f3 file2) > >(process)\n\n(note  that no MULTIOS are involved), process will be run asynchronously as far as the parent\nshell is concerned.  The workaround is:\n\n{ paste <(cut -f1 file1) <(cut -f3 file2) } > >(process)\n\nThe extra processes here are spawned from the parent shell which will wait for their  comple‐\ntion.\n\nAnother  problem  arises any time a job with a substitution that requires a temporary file is\ndisowned by the shell, including the case where `&!' or `&|' appears at the end of a  command\ncontaining  a  substitution.   In  that case the temporary file will not be cleaned up as the\nshell no longer has any memory of the job.  A workaround is to use a subshell, for example,\n\n(mycmd =(myoutput)) &!\n\nas the forked subshell will wait for the command to finish then remove the temporary file.\n\nA general workaround to ensure a process substitution endures for an  appropriate  length  of\ntime  is to pass it as a parameter to an anonymous shell function (a piece of shell code that\nis run immediately with function scope).  For example, this code:\n\n() {\nprint File $1:\ncat $1\n} =(print This be the verse)\n\noutputs something resembling the following\n\nFile /tmp/zsh6nU0kS:\nThis be the verse\n\nThe temporary file created by the process substitution will be deleted when the function  ex‐\nits.\n",
            "subsections": []
        },
        "PARAMETER EXPANSION": {
            "content": "The  character `$' is used to introduce parameter expansions.  See zshparam(1) for a descrip‐\ntion of parameters, including arrays, associative arrays, and subscript  notation  to  access\nindividual array elements.\n\nNote  in particular the fact that words of unquoted parameters are not automatically split on\nwhitespace unless the option SHWORDSPLIT is set; see references to this  option  below  for\nmore  details.   This  is  an  important  difference from other shells.  However, as in other\nshells, null words are elided from unquoted parameters' expansions.\n\nWith default options, after the assignments:\n\narray=(\"first word\" \"\" \"third word\")\nscalar=\"only word\"\n\nthen $array substitutes two words, `first word' and `third word', and $scalar  substitutes  a\nsingle  word  `only  word'.  Note that second element of array was elided.  Scalar parameters\ncan be elided too if their value is null (empty).  To avoid elision, use quoting as  follows:\n\"$scalar\" for scalars and \"${array[@]}\" or \"${(@)array}\" for arrays.  (The last two forms are\nequivalent.)\n\nParameter expansions can involve flags, as in `${(@kv)aliases}', and other operators, such as\n`${PREFIX:-\"/usr/local\"}'.   Parameter  expansions  can also be nested.  These topics will be\nintroduced below.  The full rules are complicated and are noted at the end.\n\nIn the expansions discussed below that require a pattern, the form of the pattern is the same\nas that used for filename generation; see the section `Filename Generation'.  Note that these\npatterns, along with the replacement text of any substitutions, are themselves subject to pa‐\nrameter expansion, command substitution, and arithmetic expansion.  In addition to  the  fol‐\nlowing  operations,  the  colon modifiers described in the section `Modifiers' in the section\n`History Expansion' can be applied:  for example, ${i:s/foo/bar/} performs  string  substitu‐\ntion on the expansion of parameter $i.\n\nIn  the  following  descriptions,  `word'  refers to a single word substituted on the command\nline, not necessarily a space delimited word.\n\n${name}\nThe value, if any, of the parameter name is substituted.  The braces are  required  if\nthe  expansion  is  to be followed by a letter, digit, or underscore that is not to be\ninterpreted as part of name.  In addition, more complicated forms of substitution usu‐\nally require the braces to be present; exceptions, which  only  apply  if  the  option\nKSHARRAYS  is  not set, are a single subscript or any colon modifiers appearing after\nthe name, or any of the characters `^', `=', `~', `#'  or  `+'  appearing  before  the\nname, all of which work with or without braces.\n\nIf name is an array parameter, and the KSHARRAYS option is not set, then the value of\neach  element  of name is substituted, one element per word.  Otherwise, the expansion\nresults in one word only; with KSHARRAYS, this is the first element of an array.   No\nfield  splitting  is  done  on the result unless the SHWORDSPLIT option is set.  See\nalso the flags = and s:string:.\n\n${+name}\nIf name is the name of a set parameter `1' is substituted, otherwise  `0'  is  substi‐\ntuted.\n\n${name-word}\n${name:-word}\nIf  name  is set, or in the second form is non-null, then substitute its value; other‐\nwise substitute word.  In the second form name may be omitted, in which case  word  is\nalways substituted.\n\n${name+word}\n${name:+word}\nIf  name  is  set,  or in the second form is non-null, then substitute word; otherwise\nsubstitute nothing.\n\n${name=word}\n${name:=word}\n${name::=word}\nIn the first form, if name is unset then set it to word; in the second form,  if  name\nis  unset or null then set it to word; and in the third form, unconditionally set name\nto word.  In all forms, the value of the parameter is then substituted.\n\n${name?word}\n${name:?word}\nIn the first form, if name is set, or in the second form  if  name  is  both  set  and\nnon-null,  then  substitute  its value; otherwise, print word and exit from the shell.\nInteractive shells instead return to the prompt.  If word is omitted, then a  standard\nmessage is printed.\n\nIn  any  of the above expressions that test a variable and substitute an alternate word, note\nthat you can use standard shell quoting in the word value to selectively override the  split‐\nting  done  by  the  SHWORDSPLIT  option and the = flag, but not splitting by the s:string:\nflag.\n\nIn the following expressions, when name is an array and the substitution is not quoted, or if\nthe `(@)' flag or the name[@] syntax is used, matching and replacement is performed  on  each\narray element separately.\n\n${name#pattern}\n${name##pattern}\nIf  the  pattern matches the beginning of the value of name, then substitute the value\nof name with the matched portion deleted; otherwise,  just  substitute  the  value  of\nname.   In  the  first form, the smallest matching pattern is preferred; in the second\nform, the largest matching pattern is preferred.\n\n${name%pattern}\n${name%%pattern}\nIf the pattern matches the end of the value of name, then substitute the value of name\nwith the matched portion deleted; otherwise, just substitute the value  of  name.   In\nthe  first  form,  the smallest matching pattern is preferred; in the second form, the\nlargest matching pattern is preferred.\n\n${name:#pattern}\nIf the pattern matches the value of name, then substitute the empty string; otherwise,\njust substitute the value of name.  If name is an array the  matching  array  elements\nare removed (use the `(M)' flag to remove the non-matched elements).\n\n${name:|arrayname}\nIf  arrayname is the name (N.B., not contents) of an array variable, then any elements\ncontained in arrayname are removed from the substitution of name.  If the substitution\nis scalar, either because name is a scalar variable or the expression is  quoted,  the\nelements of arrayname are instead tested against the entire expression.\n\n${name:*arrayname}\nSimilar  to  the  preceding  substitution,  but in the opposite sense, so that entries\npresent in both the original substitution and as elements of  arrayname  are  retained\nand others removed.\n\n${name:^arrayname}\n${name:^^arrayname}\nZips  two arrays, such that the output array is twice as long as the shortest (longest\nfor `:^^') of name and arrayname, with the elements alternatingly  being  picked  from\nthem.  For  `:^',  if one of the input arrays is longer, the output will stop when the\nend of the shorter array is reached.  Thus,\n\na=(1 2 3 4); b=(a b); print ${a:^b}\n\nwill output `1 a 2 b'.  For `:^^', then the input is repeated until all of the  longer\narray has been used up and the above will output `1 a 2 b 3 a 4 b'.\n\nEither  or  both  inputs may be a scalar, they will be treated as an array of length 1\nwith the scalar as the only element. If either array is empty, the other array is out‐\nput with no extra elements inserted.\n\nCurrently the following code will output `a b' and `1' as two separate elements, which\ncan be unexpected. The second print provides a workaround  which  should  continue  to\nwork if this is changed.\n\na=(a b); b=(1 2); print -l \"${a:^b}\"; print -l \"${${a:^b}}\"\n\n${name:offset}\n${name:offset:length}\nThis   syntax   gives   effects   similar   to  parameter  subscripting  in  the  form\n$name[start,end], but is compatible with other  shells;  note  that  both  offset  and\nlength are interpreted differently from the components of a subscript.\n\nIf  offset  is non-negative, then if the variable name is a scalar substitute the con‐\ntents starting offset characters from the first character of the string, and  if  name\nis  an  array substitute elements starting offset elements from the first element.  If\nlength is given, substitute that many characters or  elements,  otherwise  the  entire\nrest of the scalar or array.\n\nA  positive  offset  is always treated as the offset of a character or element in name\nfrom the first character or element of the array (this is different  from  native  zsh\nsubscript  notation).   Hence 0 refers to the first character or element regardless of\nthe setting of the option KSHARRAYS.\n\nA negative offset counts backwards from the end of the scalar or  array,  so  that  -1\ncorresponds to the last character or element, and so on.\n\nWhen  positive, length counts from the offset position toward the end of the scalar or\narray.  When negative, length counts back from the end.  If this results in a position\nsmaller than offset, a diagnostic is printed and nothing is substituted.\n\nThe option MULTIBYTE is obeyed, i.e. the offset and length count multibyte  characters\nwhere appropriate.\n\noffset  and  length  undergo the same set of shell substitutions as for scalar assign‐\nment; in addition, they are then subject to arithmetic evaluation.  Hence, for example\n\nprint ${foo:3}\nprint ${foo: 1 + 2}\nprint ${foo:$(( 1 + 2))}\nprint ${foo:$(echo 1 + 2)}\n\nall have the same effect, extracting the string starting at the  fourth  character  of\n$foo if the substitution would otherwise return a scalar, or the array starting at the\nfourth  element  if  $foo would return an array.  Note that with the option KSHARRAYS\n$foo always returns a scalar (regardless of the use of the offset syntax) and  a  form\nsuch as ${foo[*]:3} is required to extract elements of an array named foo.\n\nIf  offset is negative, the - may not appear immediately after the : as this indicates\nthe ${name:-word} form of substitution.  Instead, a space may be inserted  before  the\n-.  Furthermore, neither offset nor length may begin with an alphabetic character or &\nas  these  are used to indicate history-style modifiers.  To substitute a value from a\nvariable, the recommended approach is to precede it with a $ as this signifies the in‐\ntention (parameter substitution can easily be rendered unreadable); however, as arith‐\nmetic substitution is performed, the expression ${var: offs} does work, retrieving the\noffset from $offs.\n\nFor further compatibility with other shells there is a special case for  array  offset\n0.   This  usually accesses the first element of the array.  However, if the substitu‐\ntion refers to the positional parameter array, e.g. $@ or $*, then  offset  0  instead\nrefers  to $0, offset 1 refers to $1, and so on.  In other words, the positional para‐\nmeter array is effectively extended by prepending $0.  Hence ${*:0:1}  substitutes  $0\nand ${*:1:1} substitutes $1.\n\n${name/pattern/repl}\n${name//pattern/repl}\n${name:/pattern/repl}\nReplace  the  longest  possible match of pattern in the expansion of parameter name by\nstring repl.  The first form replaces just the first occurrence, the second  form  all\noccurrences,  and  the  third form replaces only if pattern matches the entire string.\nBoth pattern and repl are subject to double-quoted substitution, so  that  expressions\nlike ${name/$opat/$npat} will work, but obey the usual rule that pattern characters in\n$opat  are  not treated specially unless either the option GLOBSUBST is set, or $opat\nis instead substituted as ${~opat}.\n\nThe pattern may begin with a `#', in which case the pattern must match at the start of\nthe string, or `%', in which case it must match at the end of the string, or  `#%'  in\nwhich case the pattern must match the entire string.  The repl may be an empty string,\nin  which  case  the  final  `/' may also be omitted.  To quote the final `/' in other\ncases it should be preceded by a single backslash; this is not necessary  if  the  `/'\noccurs  inside  a  substituted parameter.  Note also that the `#', `%' and `#% are not\nactive if they occur inside a substituted parameter, even at the start.\n\nIf, after quoting rules apply, ${name} expands to an array, the  replacements  act  on\neach  element  individually.   Note also the effect of the I and S parameter expansion\nflags below; however, the flags M, R, B, E and N are not useful.\n\nFor example,\n\nfoo=\"twinkle twinkle little star\" sub=\"t*e\" rep=\"spy\"\nprint ${foo//${~sub}/$rep}\nprint ${(S)foo//${~sub}/$rep}\n\nHere, the `~' ensures that the text of $sub is treated as  a  pattern  rather  than  a\nplain string.  In the first case, the longest match for t*e is substituted and the re‐\nsult  is  `spy star', while in the second case, the shortest matches are taken and the\nresult is `spy spy lispy star'.\n\n${#spec}\nIf spec is one of the above substitutions, substitute the length in characters of  the\nresult  instead  of the result itself.  If spec is an array expression, substitute the\nnumber of elements of the result.  This has the side-effect that  joining  is  skipped\neven  in quoted forms, which may affect other sub-expressions in spec.  Note that `^',\n`=', and `~', below, must appear to the left of `#' when these forms are combined.\n\nIf the option POSIXIDENTIFIERS is not set, and spec is a simple name, then the braces\nare optional; this is true even for special parameters so e.g. $#- and  $#*  take  the\nlength  of  the string $- and the array $* respectively.  If POSIXIDENTIFIERS is set,\nthen braces are required for the # to be treated in this fashion.\n\n${^spec}\n${^^spec}\nTurn on the RCEXPANDPARAM option for the evaluation of spec; if the `^' is  doubled,\nturn it off.  When this option is set, array expansions of the form foo${xx}bar, where\nthe parameter xx is set to (a b c), are substituted with `fooabar foobbar foocbar' in‐\nstead of the default `fooa b cbar'.  Note that an empty array will therefore cause all\narguments to be removed.\n\nInternally, each such expansion is converted into the equivalent list for brace expan‐\nsion.   E.g.,  ${^var} becomes {$var[1],$var[2],...}, and is processed as described in\nthe section `Brace Expansion' below: note, however, the expansion happens immediately,\nwith any explicit brace expansion happening later.  If word splitting is also  in  ef‐\nfect the $var[N] may themselves be split into different list elements.\n\n${=spec}\n${==spec}\nPerform  word  splitting  using  the  rules for SHWORDSPLIT during the evaluation of\nspec, but regardless of whether the parameter appears in double quotes; if the `='  is\ndoubled,  turn  it  off.   This  forces parameter expansions to be split into separate\nwords before substitution, using IFS as a delimiter.  This is done by default in  most\nother shells.\n\nNote  that splitting is applied to word in the assignment forms of spec before the as‐\nsignment to name is performed.  This affects the result of array assignments with  the\nA flag.\n\n${~spec}\n${~~spec}\nTurn  on the GLOBSUBST option for the evaluation of spec; if the `~' is doubled, turn\nit off.  When this option is set, the string resulting from the expansion will be  in‐\nterpreted  as  a  pattern anywhere that is possible, such as in filename expansion and\nfilename generation and pattern-matching contexts like the right hand side of the  `='\nand `!=' operators in conditions.\n\nIn  nested  substitutions,  note that the effect of the ~ applies to the result of the\ncurrent level of substitution.  A surrounding pattern operation on the result may can‐\ncel it.  Hence, for example, if the parameter foo is set to *, ${~foo//\\*/*.c} is sub‐\nstituted by the pattern *.c,  which  may  be  expanded  by  filename  generation,  but\n${${~foo}//\\*/*.c} substitutes to the string *.c, which will not be further expanded.\n\nIf  a ${...} type parameter expression or a $(...) type command substitution is used in place\nof name above, it is expanded first and the result is used as if it were the value  of  name.\nThus  it is possible to perform nested operations:  ${${foo#head}%tail} substitutes the value\nof $foo with both `head' and `tail' deleted.  The form with $(...) is often useful in  combi‐\nnation  with the flags described next; see the examples below.  Each name or nested ${...} in\na parameter expansion may also be followed by a subscript expression as  described  in  Array\nParameters in zshparam(1).\n\nNote that double quotes may appear around nested expressions, in which case only the part in‐\nside  is  treated as quoted; for example, ${(f)\"$(foo)\"} quotes the result of $(foo), but the\nflag `(f)' (see below) is applied using the rules for unquoted expansions.  Note further that\nquotes are themselves nested in this context; for example, in  \"${(@f)\"$(foo)\"}\",  there  are\ntwo  sets  of quotes, one surrounding the whole expression, the other (redundant) surrounding\nthe $(foo) as before.\n",
            "subsections": [
                {
                    "name": "Parameter Expansion Flags",
                    "content": "If the opening brace is directly followed by an opening parenthesis, the  string  up  to  the\nmatching  closing  parenthesis  will be taken as a list of flags.  In cases where repeating a\nflag is meaningful, the repetitions need not be consecutive; for example, `(q%q%q)' means the\nsame thing as the more readable `(%%qqq)'.  The following flags are supported:\n\n#      Evaluate the resulting words as numeric expressions and interpret these  as  character\ncodes.  Output the corresponding characters.  Note that this form is entirely distinct\nfrom use of the # without parentheses.\n\nIf  the  MULTIBYTE option is set and the number is greater than 127 (i.e. not an ASCII\ncharacter) it is treated as a Unicode character.\n\n%      Expand all % escapes in the resulting words in the same way as in prompts (see  EXPAN‐\nSION  OF PROMPT SEQUENCES in zshmisc(1)). If this flag is given twice, full prompt ex‐\npansion is done on the resulting words, depending on the setting  of  the  PROMPTPER‐\nCENT, PROMPTSUBST and PROMPTBANG options.\n\n@      In  double quotes, array elements are put into separate words.  E.g., `\"${(@)foo}\"' is\nequivalent  to  `\"${foo[@]}\"'  and  `\"${(@)foo[1,2]}\"'  is  the  same  as   `\"$foo[1]\"\n\"$foo[2]\"'.  This is distinct from field splitting by the f, s or z flags, which still\napplies within each array element.\n\nA      Convert  the  substitution  into  an  array  expression, even if it otherwise would be\nscalar.  This has lower precedence than subscripting, so one level of nested expansion\nis required in order that subscripts apply to array elements.   Thus  ${${(A)name}[1]}\nyields the full value of name when name is scalar.\n\nThis  assigns  an  array parameter with `${...=...}', `${...:=...}' or `${...::=...}'.\nIf this flag is repeated (as in `AA'), assigns an associative  array  parameter.   As‐\nsignment  is  made  before  sorting or padding; if field splitting is active, the word\npart is split before assignment.  The name part may be a subscripted range  for  ordi‐\nnary  arrays;  when assigning an associative array, the word part must be converted to\nan array, for example by using `${(AA)=name=...}' to activate field splitting.\n\nSurrounding context such as additional nesting or use of the value in a scalar assign‐\nment may cause the array to be joined back into a single string again.\n\na      Sort in array index order; when combined with `O' sort in reverse array  index  order.\nNote  that `a' is therefore equivalent to the default but `Oa' is useful for obtaining\nan array's elements in reverse order.\n\nb      Quote with backslashes only characters that are special to pattern matching.  This  is\nuseful  when the contents of the variable are to be tested using GLOBSUBST, including\nthe ${~...} switch.\n\nQuoting using one of the q family of flags does not work for this purpose since quotes\nare not stripped from non-pattern characters by GLOBSUBST.  In other words,\n\npattern=${(q)str}\n[[ $str = ${~pattern} ]]\n\nworks if $str is `a*b' but not if it is `a b', whereas\n\npattern=${(b)str}\n[[ $str = ${~pattern} ]]\n\nis always true for any possible value of $str.\n\nc      With ${#name}, count the total number of characters in an array, as  if  the  elements\nwere  concatenated with spaces between them.  This is not a true join of the array, so\nother expressions used with this flag may have an effect on the elements of the  array\nbefore it is counted.\n\nC      Capitalize  the resulting words.  `Words' in this case refers to sequences of alphanu‐\nmeric characters separated by non-alphanumerics, not to words that result  from  field\nsplitting.\n\nD      Assume  the string or array elements contain directories and attempt to substitute the\nleading part of these by names.  The remainder of the path (the whole  of  it  if  the\nleading  part was not substituted) is then quoted so that the whole string can be used\nas a shell argument.  This is the reverse of `~' substitution:  see the section  FILE‐\nNAME EXPANSION below.\n\ne      Perform single word shell expansions, namely parameter expansion, command substitution\nand  arithmetic  expansion,  on the result. Such expansions can be nested but too deep\nrecursion may have unpredictable effects.\n\nf      Split the result of the expansion at newlines. This is a shorthand for `ps:\\n:'.\n\nF      Join the words of arrays together using newline as a separator.  This is  a  shorthand\nfor `pj:\\n:'.\n\ng:opts:\nProcess  escape sequences like the echo builtin when no options are given (g::).  With\nthe o option, octal escapes don't take a leading zero.  With the c  option,  sequences\nlike  `^X'  are  also  processed.  With the e option, processes `\\M-t' and similar se‐\nquences like the print builtin.  With both of the o and e options,  behaves  like  the\nprint builtin except that in none of these modes is `\\c' interpreted.\n\ni      Sort case-insensitively.  May be combined with `n' or `O'.\n\nk      If  name  refers  to  an associative array, substitute the keys (element names) rather\nthan the values of the elements.  Used with subscripts  (including  ordinary  arrays),\nforce  indices  or keys to be substituted even if the subscript form refers to values.\nHowever, this flag may not be combined with subscript ranges.  With the KSHARRAYS op‐\ntion a subscript `[*]' or `[@]' is needed to operate on the whole array, as usual.\n\nL      Convert all letters in the result to lower case.\n\nn      Sort decimal integers numerically; if the  first  differing  characters  of  two  test\nstrings  are  not  digits, sorting is lexical.  `+' and `-' are not treated specially;\nthey are treated as any other non-digit.  Integers with more initial zeroes are sorted\nbefore those with fewer or none.  Hence the array `foo+24 foo1 foo02 foo2  foo3  foo20\nfoo23' is sorted into the order shown.  May be combined with `i' or `O'.\n\n-      As  n, but a leading minus sign indicates a negative decimal integer.  A leading minus\nsign not followed by an integer does not trigger numeric sorting.  Note that `+' signs\nare not handled specially (this may change in the future).\n\no      Sort the resulting words in ascending order; if this appears on its own the sorting is\nlexical and case-sensitive (unless the locale renders it  case-insensitive).   Sorting\nin  ascending  order  is the default for other forms of sorting, so this is ignored if\ncombined with `a', `i', `n' or `-'.\n\nO      Sort the resulting words in descending order; `O' without `a', `i', `n' or  `-'  sorts\nin  reverse  lexical  order.  May be combined with `a', `i', `n' or `-' to reverse the\norder of sorting.\n\nP      This forces the value of the parameter name to be interpreted as a  further  parameter\nname, whose value will be used where appropriate.  Note that flags set with one of the\ntypeset family of commands (in particular case transformations) are not applied to the\nvalue of name used in this fashion.\n\nIf  used  with  a nested parameter or command substitution, the result of that will be\ntaken as a parameter name in the same way.  For example, if  you  have  `foo=bar'  and\n`bar=baz', the strings ${(P)foo}, ${(P)${foo}}, and ${(P)$(echo bar)} will be expanded\nto `baz'.\n\nLikewise,  if  the reference is itself nested, the expression with the flag is treated\nas if it were directly replaced by the parameter name.  It is an error if this  nested\nsubstitution  produces an array with more than one word.  For example, if `name=assoc'\nwhere the parameter assoc is an associative array, then `${${(P)name}[elt]}' refers to\nthe element of the associative subscripted `elt'.\n\nq      Quote characters that are special to the shell  in  the  resulting  words  with  back‐\nslashes;  unprintable  or  invalid  characters are quoted using the $'\\NNN' form, with\nseparate quotes for each octet.\n\nIf this flag is given twice, the resulting words are quoted in single quotes and if it\nis given three times, the words are quoted in double quotes; in these forms no special\nhandling of unprintable or invalid characters is attempted.  If the flag is given four\ntimes, the words are quoted in single quotes preceded by a $.  Note that in all  three\nof  these  forms quoting is done unconditionally, even if this does not change the way\nthe resulting string would be interpreted by the shell.\n\nIf a q- is given (only a single q may appear), a minimal form  of  single  quoting  is\nused  that  only quotes the string if needed to protect special characters.  Typically\nthis form gives the most readable output.\n\nIf a q+ is given, an extended form of minimal quoting is used that causes  unprintable\ncharacters  to  be rendered using $'...'.  This quoting is similar to that used by the\noutput of values by the typeset family of commands.\n\nQ      Remove one level of quotes from the resulting words.\n\nt      Use a string describing the type of the parameter where the  value  of  the  parameter\nwould usually appear. This string consists of keywords separated by hyphens (`-'). The\nfirst  keyword  in the string describes the main type, it can be one of `scalar', `ar‐\nray', `integer', `float' or `association'. The other keywords  describe  the  type  in\nmore detail:\n\nlocal  for local parameters\n\nleft   for left justified parameters\n\nrightblanks\nfor right justified parameters with leading blanks\n\nrightzeros\nfor right justified parameters with leading zeros\n\nlower  for parameters whose value is converted to all lower case when it is expanded\n\nupper  for parameters whose value is converted to all upper case when it is expanded\n\nreadonly\nfor readonly parameters\n\ntag    for tagged parameters\n\ntied   for parameters tied to another parameter in the manner of PATH (colon-separated\nlist)  and  path  (array), whether these are special parameters or user-defined\nwith `typeset -T'\n\nexport for exported parameters\n\nunique for arrays which keep only the first occurrence of duplicated values\n\nhide   for parameters with the `hide' flag\n\nhideval\nfor parameters with the `hideval' flag\n\nspecial\nfor special parameters defined by the shell\n\nu      Expand only the first occurrence of each unique word.\n\nU      Convert all letters in the result to upper case.\n\nv      Used with k, substitute (as two consecutive words) both the key and the value of  each\nassociative  array element.  Used with subscripts, force values to be substituted even\nif the subscript form refers to indices or keys.\n\nV      Make any special characters in the resulting words visible.\n\nw      With ${#name}, count words in arrays or strings; the s flag may be used to set a  word\ndelimiter.\n\nW      Similar to w with the difference that empty words between repeated delimiters are also\ncounted.\n\nX      With  this  flag,  parsing  errors  occurring with the Q, e and # flags or the pattern\nmatching forms such as `${name#pattern}' are reported.  Without the flag,  errors  are\nsilently ignored.\n\nz      Split  the  result  of the expansion into words using shell parsing to find the words,\ni.e. taking into account any quoting in the value.  Comments are not treated specially\nbut as ordinary strings, similar to interactive shells with  the  INTERACTIVECOMMENTS\noption unset (however, see the Z flag below for related options)\n\nNote  that this is done very late, even later than the `(s)' flag. So to access single\nwords in the result use nested expansions as in `${${(z)foo}[2]}'. Likewise, to remove\nthe quotes in the resulting words use `${(Q)${(z)foo}}'.\n\n0      Split the result of the expansion on null bytes.  This is a shorthand for `ps:\\0:'.\n\nThe following flags (except p) are followed by one or more arguments as shown.   Any  charac‐\nter,  or  the matching pairs `(...)', `{...}', `[...]', or `<...>', may be used in place of a\ncolon as delimiters, but note that when a flag takes more than one argument, a  matched  pair\nof delimiters must surround each argument.\n\np      Recognize the same escape sequences as the print builtin in string arguments to any of\nthe flags described below that follow this argument.\n\nAlternatively, with this option string arguments may be in the form $var in which case\nthe  value of the variable is substituted.  Note this form is strict; the string argu‐\nment does not undergo general parameter expansion.\n\nFor example,\n\nsep=:\nval=a:b:c\nprint ${(ps.$sep.)val}\n\nsplits the variable on a :.\n\n~      Strings inserted into the expansion by any of the flags below are  to  be  treated  as\npatterns.  This applies to the string arguments of flags that follow ~ within the same\nset  of parentheses.  Compare with ~ outside parentheses, which forces the entire sub‐\nstituted string to be treated as a pattern.  Hence, for example,\n\n[[ \"?\" = ${(~j.|.)array} ]]\n\ntreats `|' as a pattern and succeeds if and only if $array contains the string `?'  as\nan  element.   The ~ may be repeated to toggle the behaviour; its effect only lasts to\nthe end of the parenthesised group.\n\nj:string:\nJoin the words of arrays together using string as a separator.  Note that this  occurs\nbefore field splitting by the s:string: flag or the SHWORDSPLIT option.\n\nl:expr::string1::string2:\nPad  the  resulting  words  on  the left.  Each word will be truncated if required and\nplaced in a field expr characters wide.\n\nThe arguments :string1: and :string2: are optional; neither, the first, or both may be\ngiven.  Note that the same pairs of delimiters must be used for each of the three  ar‐\nguments.   The space to the left will be filled with string1 (concatenated as often as\nneeded) or spaces if string1 is not given.  If both string1  and  string2  are  given,\nstring2  is  inserted  once directly to the left of each word, truncated if necessary,\nbefore string1 is used to produce any remaining padding.\n\nIf either of string1 or string2 is present but empty, i.e. there  are  two  delimiters\ntogether at that point, the first character of $IFS is used instead.\n\nIf  the  MULTIBYTE  option  is  in effect, the flag m may also be given, in which case\nwidths will be used for the calculation of  padding;  otherwise  individual  multibyte\ncharacters are treated as occupying one unit of width.\n\nIf  the MULTIBYTE option is not in effect, each byte in the string is treated as occu‐\npying one unit of width.\n\nControl characters are always assumed to be one unit wide; this allows  the  mechanism\nto be used for generating repetitions of control characters.\n\nm      Only  useful  together with one of the flags l or r or with the # length operator when\nthe MULTIBYTE option is in effect.  Use the character width reported by the system  in\ncalculating  how  much  of the string it occupies or the overall length of the string.\nMost printable characters have a width of one unit, however  certain  Asian  character\nsets  and certain special effects use wider characters; combining characters have zero\nwidth.  Non-printable characters are arbitrarily counted as zero width; how they would\nactually be displayed will vary.\n\nIf the m is repeated, the character either counts zero (if it has  zero  width),  else\none.   For  printable  character strings this has the effect of counting the number of\nglyphs (visibly separate characters), except for the case where  combining  characters\nthemselves have non-zero width (true in certain alphabets).\n\nr:expr::string1::string2:\nAs  l,  but  pad the words on the right and insert string2 immediately to the right of\nthe string to be padded.\n\nLeft and right padding may be used together.  In this case the strategy  is  to  apply\nleft padding to the first half width of each of the resulting words, and right padding\nto the second half.  If the string to be padded has odd width the extra padding is ap‐\nplied on the left.\n\ns:string:\nForce  field  splitting  at  the  separator string.  Note that a string of two or more\ncharacters means that all of them must match in sequence; this differs from the treat‐\nment of two or more characters in the IFS parameter.  See also  the  =  flag  and  the\nSHWORDSPLIT option.  An empty string may also be given in which case every character\nwill be a separate element.\n\nFor historical reasons, the usual behaviour that empty array elements are retained in‐\nside double quotes is disabled for arrays generated by splitting; hence the following:\n\nline=\"one::three\"\nprint -l \"${(s.:.)line}\"\n\nproduces  two  lines of output for one and three and elides the empty field.  To over‐\nride this behaviour, supply the `(@)' flag as well, i.e.  \"${(@s.:.)line}\".\n\nZ:opts:\nAs z but takes a combination of option letters between a following pair  of  delimiter\ncharacters.   With no options the effect is identical to z.  The following options are\navailable:\n\n(Z+c+) causes comments to be parsed as a string and retained; any field in the result‐\ning array beginning with an unquoted comment character is a comment.\n\n(Z+C+) causes comments to be parsed and removed.  The rule for comments  is  standard:\nanything  between  a  word starting with the third character of $HISTCHARS, de‐\nfault #, up to the next newline is a comment.\n\n(Z+n+) causes unquoted newlines to be treated as ordinary whitespace,  else  they  are\ntreated as if they are shell code delimiters and converted to semicolons.\n\nOptions are combined within the same set of delimiters, e.g. (Z+Cn+).\n\n:flags:\nThe underscore () flag is reserved for future use.  As of this revision of zsh, there\nare  no valid flags; anything following an underscore, other than an empty pair of de‐\nlimiters, is treated as an error, and the flag itself has no effect.\n\nThe following flags are meaningful with the ${...#...} or ${...%...} forms.  The S, I, and  *\nflags may also be used with the ${.../...} forms.\n\nS      With  #  or ##, search for the match that starts closest to the start of the string (a\n`substring match'). Of all matches at a particular position, #  selects  the  shortest\nand ## the longest:\n\n% str=\"aXbXc\"\n% echo ${(S)str#X*}\nabXc\n% echo ${(S)str##X*}\na\n%\n\nWith % or %%, search for the match that starts closest to the end of the string:\n\n% str=\"aXbXc\"\n% echo ${(S)str%X*}\naXbc\n% echo ${(S)str%%X*}\naXb\n%\n\n(Note  that  %  and  %% don't search for the match that ends closest to the end of the\nstring, as one might expect.)\n\nWith substitution via ${.../...} or ${...//...}, specifies non-greedy  matching,  i.e.\nthat the shortest instead of the longest match should be replaced:\n\n% str=\"abab\"\n% echo ${str/*b/}\n\n% echo ${(S)str/*b/}\nab\n%\n\nI:expr:\nSearch  the  exprth  match (where expr evaluates to a number).  This only applies when\nsearching for substrings, either with the S flag, or with ${.../...} (only the  exprth\nmatch is substituted) or ${...//...} (all matches from the exprth on are substituted).\nThe default is to take the first match.\n\nThe  exprth  match  is counted such that there is either one or zero matches from each\nstarting position in the string, although for global substitution matches  overlapping\nprevious  replacements  are  ignored.   With the ${...%...} and ${...%%...} forms, the\nstarting position for the match moves backwards from the end as the  index  increases,\nwhile with the other forms it moves forward from the start.\n\nHence with the string\nwhich switch is the right switch for Ipswich?\nsubstitutions  of  the form ${(SI:N:)string#w*ch} as N increases from 1 will match and\nremove `which', `witch', `witch' and `wich'; the form using `##' will match and remove\n`which switch is the right switch for Ipswich', `witch is the  right  switch  for  Ip‐\nswich',  `witch  for  Ipswich'  and  `wich'.  The  form using `%' will remove the same\nmatches as for `#', but in reverse order, and the form using `%%' will remove the same\nmatches as for `##' in reverse order.\n\n*      Enable EXTENDEDGLOB for substitution via ${.../...} or ${...//...}.  Note  that  `'\ndoes not disable extendedglob.\n\nB      Include the index of the beginning of the match in the result.\n\nE      Include  the index one character past the end of the match in the result (note this is\ninconsistent with other uses of parameter index).\n\nM      Include the matched portion in the result.\n\nN      Include the length of the match in the result.\n\nR      Include the unmatched portion in the result (the Rest).\n"
                },
                {
                    "name": "Rules",
                    "content": "Here is a summary of the rules for substitution; this assumes that braces are present  around\nthe  substitution, i.e. ${...}.  Some particular examples are given below.  Note that the Zsh\nDevelopment Group accepts no responsibility for any brain damage which may occur  during  the\nreading of the following rules.\n\n1. Nested substitution\nIf multiple nested ${...} forms are present, substitution is performed from the inside\noutwards.   At each level, the substitution takes account of whether the current value\nis a scalar or an array, whether the whole substitution is in double quotes, and  what\nflags are supplied to the current level of substitution, just as if the nested substi‐\ntution  were  the  outermost.   The flags are not propagated up to enclosing substitu‐\ntions; the nested substitution will return either a scalar or an array  as  determined\nby the flags, possibly adjusted for quoting.  All the following steps take place where\napplicable at all levels of substitution.\n\nNote  that,  unless  the `(P)' flag is present, the flags and any subscripts apply di‐\nrectly to the value of the nested substitution; for example, the  expansion  ${${foo}}\nbehaves  exactly  the same as ${foo}.  When the `(P)' flag is present in a nested sub‐\nstitution, the other substitution rules are applied to the value before it  is  inter‐\npreted as a name, so ${${(P)foo}} may differ from ${(P)foo}.\n\nAt  each nested level of substitution, the substituted words undergo all forms of sin‐\ngle-word substitution (i.e. not filename generation), including command  substitution,\narithmetic  expansion  and filename expansion (i.e. leading ~ and =).  Thus, for exam‐\nple, ${${:-=cat}:h} expands to the directory where the cat program resides.  (Explana‐\ntion: the internal substitution has no parameter but a default value  =cat,  which  is\nexpanded by filename expansion to a full path; the outer substitution then applies the\nmodifier :h and takes the directory part of the path.)\n\n2. Internal parameter flags\nAny  parameter  flags  set by one of the typeset family of commands, in particular the\n-L, -R, -Z, -u and -l options for padding and capitalization, are applied directly  to\nthe  parameter value.  Note these flags are options to the command, e.g. `typeset -Z';\nthey are not the same as the flags used within parameter substitutions.\n\nAt the outermost level of substitution, the `(P)' flag (rule 4.)  ignores these trans‐\nformations and uses the unmodified value of the parameter as the name to be  replaced.\nThis  is usually the desired behavior because padding may make the value syntactically\nillegal as a parameter name, but  if  capitalization  changes  are  desired,  use  the\n${${(P)foo}} form (rule 25.).\n\n3. Parameter subscripting\nIf the value is a raw parameter reference with a subscript, such as ${var[3]}, the ef‐\nfect  of  subscripting is applied directly to the parameter.  Subscripts are evaluated\nleft to right; subsequent subscripts apply to the scalar or array value yielded by the\nprevious subscript.  Thus if var is an array, ${var[1][2]} is the second character  of\nthe  first  word,  but ${var[2,4][2]} is the entire third word (the second word of the\nrange of words two through four of the original array).  Any number of subscripts  may\nappear.   Flags such as `(k)' and `(v)' which alter the result of subscripting are ap‐\nplied.\n\n4. Parameter name replacement\nAt the outermost level of nesting only, the `(P)' flag is applied.   This  treats  the\nvalue  so  far  as a parameter name (which may include a subscript expression) and re‐\nplaces that with the corresponding value.  This replacement occurs later if the  `(P)'\nflag appears in a nested substitution.\n\nIf  the value so far names a parameter that has internal flags (rule 2.), those inter‐\nnal flags are applied to the new value after replacement.\n\n5. Double-quoted joining\nIf the value after this process is an array, and the substitution  appears  in  double\nquotes,  and neither an `(@)' flag nor a `#' length operator is present at the current\nlevel, then words of the value are joined with the first character  of  the  parameter\n$IFS, by default a space, between each word (single word arrays are not modified).  If\nthe `(j)' flag is present, that is used for joining instead of $IFS.\n\n6. Nested subscripting\nAny  remaining subscripts (i.e. of a nested substitution) are evaluated at this point,\nbased on whether the value is an array or a scalar.  As with 3.,  multiple  subscripts\ncan appear.  Note that ${foo[2,4][2]} is thus equivalent to ${${foo[2,4]}[2]} and also\nto  \"${${(@)foo[2,4]}[2]}\"  (the  nested substitution returns an array in both cases),\nbut not to \"${${foo[2,4]}[2]}\" (the nested substitution returns a  scalar  because  of\nthe quotes).\n\n7. Modifiers\nAny modifiers, as specified by a trailing `#', `%', `/' (possibly doubled) or by a set\nof  modifiers  of the form `:...' (see the section `Modifiers' in the section `History\nExpansion'), are applied to the words of the value at this level.\n\n8. Character evaluation\nAny `(#)' flag is applied, evaluating the result so far numerically as a character.\n\n9. Length\nAny initial `#' modifier, i.e. in the form ${#var}, is used to evaluate the length  of\nthe expression so far.\n\n10. Forced joining\nIf  the  `(j)'  flag  is  present, or no `(j)' flag is present but the string is to be\nsplit as given by rule 11., and joining did not take place at rule 5.,  any  words  in\nthe value are joined together using the given string or the first character of $IFS if\nnone.   Note that the `(F)' flag implicitly supplies a string for joining in this man‐\nner.\n\n11. Simple word splitting\nIf one of the `(s)' or `(f)' flags are present, or the `=' specifier was present (e.g.\n${=var}), the word is split on occurrences of the specified string,  or  (for  =  with\nneither of the two flags present) any of the characters in $IFS.\n\nIf  no  `(s)',  `(f)'  or  `='  was  given,  but the word is not quoted and the option\nSHWORDSPLIT is set, the word is split on occurrences of any  of  the  characters  in\n$IFS.  Note this step, too, takes place at all levels of a nested substitution.\n\n12. Case modification\nAny case modification from one of the flags `(L)', `(U)' or `(C)' is applied.\n\n13. Escape sequence replacement\nFirst  any  replacements from the `(g)' flag are performed, then any prompt-style for‐\nmatting from the `(%)' family of flags is applied.\n\n14. Quote application\nAny quoting or unquoting using `(q)' and `(Q)' and related flags is applied.\n\n15. Directory naming\nAny directory name substitution using `(D)' flag is applied.\n\n16. Visibility enhancement\nAny modifications to make characters visible using the `(V)' flag are applied.\n\n17. Lexical word splitting\nIf the '(z)' flag or one of the forms of the '(Z)' flag is present, the word is  split\nas  if  it were a shell command line, so that quotation marks and other metacharacters\nare used to decide what constitutes a word.  Note this form of splitting  is  entirely\ndistinct  from  that  described  by rule 11.: it does not use $IFS, and does not cause\nforced joining.\n\n18. Uniqueness\nIf the result is an array and the `(u)' flag was present, duplicate elements  are  re‐\nmoved from the array.\n\n19. Ordering\nIf  the  result is still an array and one of the `(o)' or `(O)' flags was present, the\narray is reordered.\n"
                },
                {
                    "name": "20. RC_EXPAND_PARAM",
                    "content": "At this point the decision is made whether any resulting array elements are to be com‐\nbined element by element with surrounding text, as given by either the RCEXPANDPARAM\noption or the `^' flag.\n\n21. Re-evaluation\nAny `(e)' flag is applied to the value, forcing it to be re-examined for new parameter\nsubstitutions, but also for command and arithmetic substitutions.\n\n22. Padding\nAny padding of the value by the `(l.fill.)' or `(r.fill.)' flags is applied.\n\n23. Semantic joining\nIn contexts where expansion semantics requires a single word to result, all words  are\nrejoined with the first character of IFS between.  So in `${(P)${(f)lines}}' the value\nof  ${lines} is split at newlines, but then must be joined again before the `(P)' flag\ncan be applied.\n\nIf a single word is not required, this rule is skipped.\n\n24. Empty argument removal\nIf the substitution does not appear in double quotes, any resulting zero-length  argu‐\nment,  whether from a scalar or an element of an array, is elided from the list of ar‐\nguments inserted into the command line.\n\nStrictly speaking, the removal happens later as the same happens with other  forms  of\nsubstitution;  the  point to note here is simply that it occurs after any of the above\nparameter operations.\n\n25. Nested parameter name replacement\nIf the `(P)' flag is present and rule 4. has not applied, the value so far is  treated\nas  a  parameter name (which may include a subscript expression) and replaced with the\ncorresponding value, with internal flags (rule 2.) applied to the new value.\n"
                },
                {
                    "name": "Examples",
                    "content": "The flag f is useful to split a  double-quoted  substitution  line  by  line.   For  example,\n${(f)\"$(<file)\"}  substitutes the contents of file divided so that each line is an element of\nthe resulting array.  Compare this with the effect of $(<file) alone, which divides the  file\nup  by  words, or the same inside double quotes, which makes the entire content of the file a\nsingle string.\n\nThe following illustrates the rules for nested parameter expansions.  Suppose that $foo  con‐\ntains the array (bar baz):\n"
                },
                {
                    "name": "\"${(@)${foo}[1]}\"",
                    "content": "This  produces the result b.  First, the inner substitution \"${foo}\", which has no ar‐\nray (@) flag, produces a  single  word  result  \"bar  baz\".   The  outer  substitution\n\"${(@)...[1]}\"  detects  that  this  is a scalar, so that (despite the `(@)' flag) the\nsubscript picks the first character.\n"
                },
                {
                    "name": "\"${${(@)foo}[1]}\"",
                    "content": "This produces the result `bar'.  In this case, the inner substitution \"${(@)foo}\" pro‐\nduces the array `(bar baz)'.  The outer substitution \"${...[1]}\" detects that this  is\nan array and picks the first word.  This is similar to the simple case \"${foo[1]}\".\n\nAs  an  example  of the rules for word splitting and joining, suppose $foo contains the array\n`(ax1 bx1)'.  Then\n"
                },
                {
                    "name": "${(s/x/)foo}",
                    "content": "produces the words `a', `1 b' and `1'.\n"
                },
                {
                    "name": "${(j/x/s/x/)foo}",
                    "content": "produces `a', `1', `b' and `1'.\n\n${(s/x/)foo%%1*}\nproduces `a' and ` b' (note the extra space).  As substitution  occurs  before  either\njoining or splitting, the operation  first generates the modified array (ax bx), which\nis  joined  to give \"ax bx\", and then split to give `a', ` b' and `'.  The final empty\nstring will then be elided, as it is not in double quotes.\n"
                }
            ]
        },
        "COMMAND SUBSTITUTION": {
            "content": "A command enclosed in parentheses preceded by a dollar sign, like `$(...)',  or  quoted  with\ngrave accents, like ``...`', is replaced with its standard output, with any trailing newlines\ndeleted.   If  the  substitution  is not enclosed in double quotes, the output is broken into\nwords using the IFS parameter.\n\nThe substitution `$(cat foo)' may be replaced by the faster `$(<foo)'.  In this case foo  un‐\ndergoes  single  word  shell expansions (parameter expansion, command substitution and arith‐\nmetic expansion), but not filename generation.\n\nIf the option GLOBSUBST is set, the result of any unquoted command  substitution,  including\nthe special form just mentioned, is eligible for filename generation.\n",
            "subsections": []
        },
        "ARITHMETIC EXPANSION": {
            "content": "A  string  of the form `$[exp]' or `$((exp))' is substituted with the value of the arithmetic\nexpression exp.  exp is subjected to parameter expansion, command substitution and arithmetic\nexpansion before it is evaluated.  See the section `Arithmetic Evaluation'.\n",
            "subsections": []
        },
        "BRACE EXPANSION": {
            "content": "A string of the form `foo{xx,yy,zz}bar' is  expanded  to  the  individual  words  `fooxxbar',\n`fooyybar'  and `foozzbar'.  Left-to-right order is preserved.  This construct may be nested.\nCommas may be quoted in order to include them literally in a word.\n\nAn expression of the form `{n1..n2}', where n1 and n2 are integers, is expanded to every num‐\nber between n1 and n2 inclusive.  If either number begins with a zero, all the resulting num‐\nbers will be padded with leading zeroes to that minimum width, but for negative numbers the -\ncharacter is also included in the width.  If the numbers are in decreasing order the  result‐\ning sequence will also be in decreasing order.\n\nAn  expression  of the form `{n1..n2..n3}', where n1, n2, and n3 are integers, is expanded as\nabove, but only every n3th number starting from n1 is output.  If n3 is negative the  numbers\nare output in reverse order, this is slightly different from simply swapping n1 and n2 in the\ncase  that the step n3 doesn't evenly divide the range.  Zero padding can be specified in any\nof the three numbers,  specifying  it  in  the  third  can  be  useful  to  pad  for  example\n`{-99..100..01}'  which  is not possible to specify by putting a 0 on either of the first two\nnumbers (i.e. pad to two characters).\n\nAn expression of the form `{c1..c2}', where c1 and c2 are single  characters  (which  may  be\nmultibyte  characters), is expanded to every character in the range from c1 to c2 in whatever\ncharacter sequence is used internally.  For characters with code points below 128 this is  US\nASCII  (this  is  the  only  case most users will need).  If any intervening character is not\nprintable, appropriate quotation is used to render it printable.  If the  character  sequence\nis reversed, the output is in reverse order, e.g. `{d..a}' is substituted as `d c b a'.\n\nIf  a  brace expression matches none of the above forms, it is left unchanged, unless the op‐\ntion BRACECCL (an abbreviation for `brace character class') is set.  In that case, it is ex‐\npanded to a list of the individual characters between the braces sorted into the order of the\ncharacters in the ASCII character set (multibyte characters are not currently handled).   The\nsyntax  is  similar to a [...] expression in filename generation: `-' is treated specially to\ndenote a range of characters, but `^' or `!' as the first character is treated normally.  For\nexample, `{abcdef0-9}' expands to 16 words 0 1 2 3 4 5 6 7 8 9 a b c d e f.\n\nNote that brace expansion is not part of filename generation (globbing); an  expression  such\nas  */{foo,bar}  is  split into two separate words */foo and */bar before filename generation\ntakes place.  In particular, note that this is liable to produce a `no match' error if either\nof the two expressions does not match; this is to be contrasted with  */(foo|bar),  which  is\ntreated as a single pattern but otherwise has similar effects.\n\nTo  combine brace expansion with array expansion, see the ${^spec} form described in the sec‐\ntion `Parameter Expansion' above.\n",
            "subsections": []
        },
        "FILENAME EXPANSION": {
            "content": "Each word is checked to see if it begins with an unquoted `~'.  If it does, then the word  up\nto  a  `/', or the end of the word if there is no `/', is checked to see if it can be substi‐\ntuted in one of the ways described here.  If so, then the `~' and the checked portion are re‐\nplaced with the appropriate substitute value.\n\nA `~' by itself is replaced by the value of $HOME.  A `~' followed by a `+' or a `-'  is  re‐\nplaced by current or previous working directory, respectively.\n\nA  `~'  followed  by  a number is replaced by the directory at that position in the directory\nstack.  `~0' is equivalent to `~+', and `~1' is the top of the stack.   `~+'  followed  by  a\nnumber is replaced by the directory at that position in the directory stack.  `~+0' is equiv‐\nalent  to  `~+', and `~+1' is the top of the stack.  `~-' followed by a number is replaced by\nthe directory that many positions from the bottom of the stack.  `~-0' is the bottom  of  the\nstack.  The PUSHDMINUS option exchanges the effects of `~+' and `~-' where they are followed\nby a number.\n",
            "subsections": [
                {
                    "name": "Dynamic named directories",
                    "content": "If the function zshdirectoryname exists, or the shell variable zshdirectorynamefunctions\nexists  and contains an array of function names, then the functions are used to implement dy‐\nnamic directory naming.  The functions are tried in order until one returns status  zero,  so\nit  is  important that functions test whether they can handle the case in question and return\nan appropriate status.\n\nA `~' followed by a string namstr in unquoted square brackets is treated specially as  a  dy‐\nnamic  directory name.  Note that the first unquoted closing square bracket always terminates\nnamstr.  The shell function is passed two arguments: the string n (for name) and namstr.   It\nshould either set the array reply to a single element which is the directory corresponding to\nthe  name  and  return  status zero (executing an assignment as the last statement is usually\nsufficient), or it should return status non-zero.  In the former case the element of reply is\nused as the directory; in the latter case the substitution is deemed to have failed.  If  all\nfunctions fail and the option NOMATCH is set, an error results.\n\nThe functions defined as above are also used to see if a directory can be turned into a name,\nfor  example when printing the directory stack or when expanding %~ in prompts.  In this case\neach function is passed two arguments: the string d (for directory) and the candidate for dy‐\nnamic naming.  The function should either return non-zero status, if the directory cannot  be\nnamed by the function, or it should set the array reply to consist of two elements: the first\nis  the  dynamic  name for the directory (as would appear within `~[...]'), and the second is\nthe prefix length of the directory to be replaced.  For example, if the  trial  directory  is\n/home/myname/src/zsh  and  the dynamic name for /home/myname/src (which has 16 characters) is\ns, then the function sets\n\nreply=(s 16)\n\nThe directory name so returned is compared with possible static names for parts of the direc‐\ntory path, as described below; it is used if the prefix length matched (16 in the example) is\nlonger than that matched by any static name.\n\nIt is not a requirement that a function implements both n and d calls; for example, it  might\nbe appropriate for certain dynamic forms of expansion not to be contracted to names.  In that\ncase any call with the first argument d should cause a non-zero status to be returned.\n\nThe  completion  system calls `zshdirectoryname c' followed by equivalent calls to elements\nof the array zshdirectorynamefunctions, if it exists, in order to complete  dynamic  names\nfor  directories.   The  code  for this should be as for any other completion function as de‐\nscribed in zshcompsys(1).\n\nAs a working example, here is a function that expands any dynamic names  beginning  with  the\nstring p: to directories below /home/pws/perforce.  In this simple case a static name for the\ndirectory would be just as effective.\n\nzshdirectoryname() {\nemulate -L zsh\nsetopt extendedglob\nlocal -a match mbegin mend\nif [[ $1 = d ]]; then\n# turn the directory into a name\nif [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then\ntypeset -ga reply\nreply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) )\nelse\nreturn 1\nfi\nelif [[ $1 = n ]]; then\n# turn the name into a directory\n[[ $2 != (#b)p:(?*) ]] && return 1\ntypeset -ga reply\nreply=(/home/pws/perforce/$match[1])\nelif [[ $1 = c ]]; then\n# complete names\nlocal expl\nlocal -a dirs\ndirs=(/home/pws/perforce/*(/:t))\ndirs=(p:${^dirs})\nwanted dynamic-dirs expl 'dynamic directory' compadd -S\\] -a dirs\nreturn\nelse\nreturn 1\nfi\nreturn 0\n}\n"
                },
                {
                    "name": "Static named directories",
                    "content": "A `~' followed by anything not already covered consisting of any number of alphanumeric char‐\nacters or underscore (`'), hyphen (`-'), or dot (`.') is looked up as a named directory, and\nreplaced by the value of that named directory if found.  Named directories are typically home\ndirectories  for  users on the system.  They may also be defined if the text after the `~' is\nthe name of a string shell parameter whose value begins  with  a  `/'.   Note  that  trailing\nslashes  will be removed from the path to the directory (though the original parameter is not\nmodified).\n\nIt is also possible to define directory names using the -d option to the hash builtin.\n\nWhen the shell prints a path (e.g. when expanding %~ in prompts or when printing  the  direc‐\ntory  stack),  the  path is checked to see if it has a named directory as its prefix.  If so,\nthen the prefix portion is replaced with a `~' followed by the name of  the  directory.   The\nshorter of the two ways of referring to the directory is used, i.e. either the directory name\nor  the  full  path;  the  name is used if they are the same length.  The parameters $PWD and\n$OLDPWD are never abbreviated in this fashion.\n"
                },
                {
                    "name": "`=' expansion",
                    "content": "If a word begins with an unquoted `=' and the EQUALS option is set, the remainder of the word\nis taken as the name of a command.  If a command exists by that name, the word is replaced by\nthe full pathname of the command.\n"
                },
                {
                    "name": "Notes",
                    "content": "Filename expansion is performed on the right hand side of a parameter  assignment,  including\nthose appearing after commands of the typeset family.  In this case, the right hand side will\nbe treated as a colon-separated list in the manner of the PATH parameter, so that a `~' or an\n`=' following a `:' is eligible for expansion.  All such behaviour can be disabled by quoting\nthe  `~',  the  `=', or the whole expression (but not simply the colon); the EQUALS option is\nalso respected.\n\nIf the option MAGICEQUALSUBST is set, any unquoted shell  argument  in  the  form  `identi‐\nfier=expression'  becomes eligible for file expansion as described in the previous paragraph.\nQuoting the first `=' also inhibits this.\n"
                }
            ]
        },
        "FILENAME GENERATION": {
            "content": "If a word contains an unquoted instance of one of the characters `*', `(', `|', `<', `[',  or\n`?',  it  is  regarded as a pattern for filename generation, unless the GLOB option is unset.\nIf the EXTENDEDGLOB option is set, the `^' and `#' characters also denote a pattern;  other‐\nwise they are not treated specially by the shell.\n\nThe  word is replaced with a list of sorted filenames that match the pattern.  If no matching\npattern is found, the shell gives an error message, unless the NULLGLOB option  is  set,  in\nwhich case the word is deleted; or unless the NOMATCH option is unset, in which case the word\nis left unchanged.\n\nIn  filename  generation,  the  character `/' must be matched explicitly; also, a `.' must be\nmatched explicitly at the beginning of a pattern or after a `/', unless the GLOBDOTS  option\nis set.  No filename generation pattern matches the files `.' or `..'.  In other instances of\npattern matching, the `/' and `.' are not treated specially.\n",
            "subsections": [
                {
                    "name": "Glob Operators",
                    "content": "*      Matches any string, including the null string.\n\n?      Matches any character.\n\n[...]  Matches any of the enclosed characters.  Ranges of characters can be specified by sep‐\narating  two  characters by a `-'.  A `-' or `]' may be matched by including it as the\nfirst character in the list.  There are also several named classes of  characters,  in\nthe  form  `[:name:]'  with the following meanings.  The first set use the macros pro‐\nvided by the operating system to test for the given character combinations,  including\nany modifications due to local language settings, see ctype(3):\n\n[:alnum:]\nThe character is alphanumeric\n\n[:alpha:]\nThe character is alphabetic\n\n[:ascii:]\nThe  character  is  7-bit,  i.e. is a single-byte character without the top bit\nset.\n\n[:blank:]\nThe character is a blank character\n\n[:cntrl:]\nThe character is a control character\n\n[:digit:]\nThe character is a decimal digit\n\n[:graph:]\nThe character is a printable character other than whitespace\n\n[:lower:]\nThe character is a lowercase letter\n\n[:print:]\nThe character is printable\n\n[:punct:]\nThe character is printable but neither alphanumeric nor whitespace\n\n[:space:]\nThe character is whitespace\n\n[:upper:]\nThe character is an uppercase letter\n\n[:xdigit:]\nThe character is a hexadecimal digit\n\nAnother set of named classes is handled internally by the shell and is  not  sensitive\nto the locale:\n\n[:IDENT:]\nThe  character is allowed to form part of a shell identifier, such as a parame‐\nter name; this test respects the POSIXIDENTIFIERS option\n\n[:IFS:]\nThe character is used as an input field separator, i.e. is contained in the IFS\nparameter\n\n[:IFSSPACE:]\nThe character is an IFS white space character; see the documentation for IFS in\nthe zshparam(1) manual page.\n\n[:INCOMPLETE:]\nMatches a byte that starts an incomplete multibyte character.  Note that  there\nmay be a sequence of more than one bytes that taken together form the prefix of\na multibyte character.  To test for a potentially incomplete byte sequence, use\nthe  pattern  `[[:INCOMPLETE:]]*'.   This  will never match a sequence starting\nwith a valid multibyte character.\n\n[:INVALID:]\nMatches a byte that does not start a valid multibyte character.  Note this  may\nbe  a  continuation  byte of an incomplete multibyte character as any part of a\nmultibyte string consisting of invalid and incomplete multibyte  characters  is\ntreated as single bytes.\n\n[:WORD:]\nThe character is treated as part of a word; this test is sensitive to the value\nof the WORDCHARS parameter\n\nNote that the square brackets are additional to those enclosing the whole set of char‐\nacters,  so to test for a single alphanumeric character you need `[[:alnum:]]'.  Named\ncharacter sets can be used alongside other types, e.g. `[[:alpha:]0-9]'.\n\n[^...]\n[!...] Like [...], except that it matches any character which is not in the given set.\n\n<[x]-[y]>\nMatches any number in the range x to y, inclusive.  Either of the numbers may be omit‐\nted to make the range open-ended; hence `<->' matches any number.  To match individual\ndigits, the [...] form is more efficient.\n\nBe careful when using other wildcards adjacent to patterns of this form; for  example,\n<0-9>* will actually match any number whatsoever at the start of the string, since the\n`<0-9>' will match the first digit, and the `*' will match any others.  This is a trap\nfor  the unwary, but is in fact an inevitable consequence of the rule that the longest\npossible match always succeeds.  Expressions such as `<0-9>[^[:digit:]]*' can be  used\ninstead.\n\n(...)  Matches  the  enclosed pattern.  This is used for grouping.  If the KSHGLOB option is\nset, then a `@', `*', `+', `?' or `!' immediately preceding the `('  is  treated  spe‐\ncially,  as  detailed  below.  The option SHGLOB prevents bare parentheses from being\nused in this way, though the KSHGLOB option is still available.\n\nNote that grouping cannot extend over multiple directories: it is an error to  have  a\n`/'  within  a  group  (this  only  applies for patterns used in filename generation).\nThere is one exception:  a group of the form (pat/)# appearing as a complete path seg‐\nment can match a sequence of directories.  For example, foo/(a*/)#bar matches foo/bar,\nfoo/any/bar, foo/any/anyother/bar, and so on.\n\nx|y    Matches either x or y.  This operator has lower precedence than any  other.   The  `|'\ncharacter  must be within parentheses, to avoid interpretation as a pipeline.  The al‐\nternatives are tried in order from left to right.\n\n^x     (Requires EXTENDEDGLOB to be set.)  Matches anything except the pattern x.  This  has\na  higher  precedence  than  `/',  so `^foo/bar' will search directories in `.' except\n`./foo' for a file named `bar'.\n\nx~y    (Requires EXTENDEDGLOB to be set.)  Match anything that matches  the  pattern  x  but\ndoes  not  match  y.   This  has  lower  precedence  than  any operator except `|', so\n`*/*~foo/bar' will search for all files in all directories in `.'   and  then  exclude\n`foo/bar'  if  there  was  such  a  match.   Multiple  patterns  can  be  excluded  by\n`foo~bar~baz'.  In the exclusion pattern (y), `/' and `.' are  not  treated  specially\nthe way they usually are in globbing.\n\nx#     (Requires  EXTENDEDGLOB  to be set.)  Matches zero or more occurrences of the pattern\nx.  This operator has high precedence; `12#' is equivalent  to  `1(2#)',  rather  than\n`(12)#'.   It  is an error for an unquoted `#' to follow something which cannot be re‐\npeated; this includes an empty string, a pattern already followed by `##',  or  paren‐\ntheses  when part of a KSHGLOB pattern (for example, `!(foo)#' is invalid and must be\nreplaced by `*(!(foo))').\n\nx##    (Requires EXTENDEDGLOB to be set.)  Matches one or more occurrences of the pattern x.\nThis operator has high precedence; `12##'  is  equivalent  to  `1(2##)',  rather  than\n`(12)##'.   No more than two active `#' characters may appear together.  (Note the po‐\ntential clash with glob qualifiers in the form  `1(2##)'  which  should  therefore  be\navoided.)\n"
                },
                {
                    "name": "ksh-like Glob Operators",
                    "content": "If the KSHGLOB option is set, the effects of parentheses can be modified by a preceding `@',\n`*',  `+',  `?' or `!'.  This character need not be unquoted to have special effects, but the\n`(' must be.\n\n@(...) Match the pattern in the parentheses.  (Like `(...)'.)\n\n*(...) Match any number of occurrences.  (Like  `(...)#',  except  that  recursive  directory\nsearching is not supported.)\n\n+(...) Match  at  least  one  occurrence.   (Like  `(...)##', except that recursive directory\nsearching is not supported.)\n\n?(...) Match zero or one occurrence.  (Like `(|...)'.)\n\n!(...) Match anything but the expression in parentheses.  (Like `(^(...))'.)\n"
                },
                {
                    "name": "Precedence",
                    "content": "The precedence of the operators given above is (highest) `^', `/', `~', `|' (lowest); the re‐\nmaining operators are simply treated from left to right as part of a  string,  with  `#'  and\n`##'  applying  to  the  shortest  possible  preceding  unit (i.e. a character, `?', `[...]',\n`<...>', or a parenthesised expression).  As mentioned above, a `/' used as a directory sepa‐\nrator may not appear inside parentheses, while a `|' must do so; in patterns  used  in  other\ncontexts  than  filename  generation  (for  example,  in  case  statements  and  tests within\n`[[...]]'), a `/' is not special; and `/' is also not special after a `~'  appearing  outside\nparentheses in a filename pattern.\n"
                },
                {
                    "name": "Globbing Flags",
                    "content": "There  are  various flags which affect any text to their right up to the end of the enclosing\ngroup or to the end of the pattern; they require the EXTENDEDGLOB option. All take the  form\n(#X) where X may have one of the following forms:\n\ni      Case  insensitive:  upper or lower case characters in the pattern match upper or lower\ncase characters.\n\nl      Lower case characters in the pattern match upper or lower case characters; upper  case\ncharacters in the pattern still only match upper case characters.\n\nI      Case sensitive:  locally negates the effect of i or l from that point on.\n\nb      Activate backreferences for parenthesised groups in the pattern; this does not work in\nfilename  generation.  When a pattern with a set of active parentheses is matched, the\nstrings matched by the groups are stored in the array $match, the indices of  the  be‐\nginning of the matched parentheses in the array $mbegin, and the indices of the end in\nthe  array  $mend,  with  the  first  element of each array corresponding to the first\nparenthesised group, and so on.  These arrays are not otherwise special to the  shell.\nThe  indices  use the same convention as does parameter substitution, so that elements\nof $mend and $mbegin may be used in subscripts; the KSHARRAYS  option  is  respected.\nSets  of  globbing  flags are not considered parenthesised groups; only the first nine\nactive parentheses can be referenced.\n\nFor example,\n\nfoo=\"astringwithamessage\"\nif [[ $foo = (a|an)(#b)(*) ]]; then\nprint ${foo[$mbegin[1],$mend[1]]}\nfi\n\nprints `stringwithamessage'.  Note that the first set of parentheses is before  the\n(#b) and does not create a backreference.\n\nBackreferences work with all forms of pattern matching other than filename generation,\nbut note that when performing matches on an entire array, such as ${array#pattern}, or\na  global  substitution,  such as ${param//pat/repl}, only the data for the last match\nremains available.  In the case of global replacements this may still be useful.   See\nthe example for the m flag below.\n\nThe  numbering of backreferences strictly follows the order of the opening parentheses\nfrom left to right in the pattern string, although sets of parentheses may be  nested.\nThere  are special rules for parentheses followed by `#' or `##'.  Only the last match\nof the parenthesis is remembered: for example, in `[[ abab = (#b)([ab])# ]]', only the\nfinal `b' is stored in match[1].  Thus extra parentheses may be necessary to match the\ncomplete segment: for example, use `X((ab|cd)#)Y' to match a whole  string  of  either\n`ab' or `cd' between `X' and `Y', using the value of $match[1] rather than $match[2].\n\nIf  the match fails none of the parameters is altered, so in some cases it may be nec‐\nessary to initialise them beforehand.  If some of the backreferences fail to match  --\nwhich  happens if they are in an alternate branch which fails to match, or if they are\nfollowed by # and matched zero times -- then the matched string is set  to  the  empty\nstring, and the start and end indices are set to -1.\n\nPattern matching with backreferences is slightly slower than without.\n\nB      Deactivate backreferences, negating the effect of the b flag from that point on.\n\ncN,M   The flag (#cN,M) can be used anywhere that the # or ## operators can be used except in\nthe  expressions  `(*/)#'  and  `(*/)##' in filename generation, where `/' has special\nmeaning; it cannot be combined with other globbing flags and a bad pattern  error  oc‐\ncurs  if  it is misplaced.  It is equivalent to the form {N,M} in regular expressions.\nThe previous character or group is required to match between N and M times, inclusive.\nThe form (#cN) requires exactly N matches; (#c,M) is equivalent to specifying N as  0;\n(#cN,) specifies that there is no maximum limit on the number of matches.\n\nm      Set  references  to  the  match data for the entire string matched; this is similar to\nbackreferencing and does not work in filename generation.  The flag must be in  effect\nat  the end of the pattern, i.e. not local to a group. The parameters $MATCH,  $MBEGIN\nand $MEND will be set to the string matched and to the indices of  the  beginning  and\nend  of  the string, respectively.  This is most useful in parameter substitutions, as\notherwise the string matched is obvious.\n\nFor example,\n\narr=(veldt jynx grimps waqf zho buck)\nprint ${arr//(#m)[aeiou]/${(U)MATCH}}\n\nforces all the matches (i.e. all vowels) into uppercase, printing `vEldt  jynx  grImps\nwAqf zhO bUck'.\n\nUnlike  backreferences,  there  is  no speed penalty for using match references, other\nthan the extra substitutions required for the replacement strings in cases such as the\nexample shown.\n\nM      Deactivate the m flag, hence no references to match data will be created.\n\nanum   Approximate matching: num errors are allowed in the string  matched  by  the  pattern.\nThe rules for this are described in the next subsection.\n\ns, e   Unlike  the  other  flags, these have only a local effect, and each must appear on its\nown:  `(#s)' and `(#e)' are the only valid forms.  The `(#s)' flag  succeeds  only  at\nthe start of the test string, and the `(#e)' flag succeeds only at the end of the test\nstring; they correspond to `^' and `$' in standard regular expressions.  They are use‐\nful  for  matching  path  segments in patterns other than those in filename generation\n(where  path  segments  are  in  any   case   treated   separately).    For   example,\n`*((#s)|/)test((#e)|/)*'  matches  a  path  segment  `test'  in  any  of the following\nstrings: test, test/at/start, at/end/test, in/test/middle.\n\nAnother use is in parameter substitution; for example `${array/(#s)A*Z(#e)}' will  re‐\nmove  only  elements  of  an  array which match the complete pattern `A*Z'.  There are\nother ways of performing many operations of this type, however the combination of  the\nsubstitution  operations `/' and `//' with the `(#s)' and `(#e)' flags provides a sin‐\ngle simple and memorable method.\n\nNote that assertions of the form `(^(#s))' also work, i.e. match  anywhere  except  at\nthe  start  of the string, although this actually means `anything except a zero-length\nportion at the start  of  the  string';  you  need  to  use  `(\"\"~(#s))'  to  match  a\nzero-length portion of the string not at the start.\n\nq      A  `q'  and everything up to the closing parenthesis of the globbing flags are ignored\nby the pattern matching code.  This is intended to support the use of glob qualifiers,\nsee below.  The result is that the pattern `(#b)(*).c(#q.)' can be used both for glob‐\nbing and for matching against a string.  In the  former  case,  the  `(#q.)'  will  be\ntreated  as  a  glob  qualifier and the `(#b)' will not be useful, while in the latter\ncase the `(#b)' is useful for backreferences and the `(#q.)' will  be  ignored.   Note\nthat  colon  modifiers in the glob qualifiers are also not applied in ordinary pattern\nmatching.\n\nu      Respect the current locale in determining the presence of multibyte  characters  in  a\npattern,  provided  the shell was compiled with MULTIBYTESUPPORT.  This overrides the\nMULTIBYTE option; the  default  behaviour  is  taken  from  the  option.   Compare  U.\n(Mnemonic:  typically multibyte characters are from Unicode in the UTF-8 encoding, al‐\nthough any extension of ASCII supported by the system library may be used.)\n\nU      All characters are considered to be a single byte long.   The  opposite  of  u.   This\noverrides the MULTIBYTE option.\n\nFor  example,  the  test  string  fooxx  can  be matched by the pattern (#i)FOOXX, but not by\n(#l)FOOXX, (#i)FOO(#I)XX or ((#i)FOOX)X.  The string (#ia2)readme specifies  case-insensitive\nmatching of readme with up to two errors.\n\nWhen  using  the  ksh syntax for grouping both KSHGLOB and EXTENDEDGLOB must be set and the\nleft parenthesis should be preceded by @.  Note also that the flags do not affect letters in‐\nside [...] groups, in other words (#i)[a-z] still matches only lowercase  letters.   Finally,\nnote  that when examining whole paths case-insensitively every directory must be searched for\nall files which match, so that a pattern of the form (#i)/foo/bar/... is potentially slow.\n"
                },
                {
                    "name": "Approximate Matching",
                    "content": "When matching approximately, the shell keeps a count of the errors found, which cannot exceed\nthe number specified in the (#anum) flags.  Four types of error are recognised:\n\n1.     Different characters, as in fooxbar and fooybar.\n\n2.     Transposition of characters, as in banana and abnana.\n\n3.     A character missing in the target string, as with the pattern road and  target  string\nrod.\n\n4.     An extra character appearing in the target string, as with stove and strove.\n\nThus,  the  pattern (#a3)abcd matches dcba, with the errors occurring by using the first rule\ntwice and the second once, grouping the string as [d][cb][a] and [a][bc][d].\n\nNon-literal parts of the pattern  must  match  exactly,  including  characters  in  character\nranges:  hence  (#a1)???  matches strings of length four, by applying rule 4 to an empty part\nof the pattern, but not strings of length two, since all the ? must match.  Other  characters\nwhich  must match exactly are initial dots in filenames (unless the GLOBDOTS option is set),\nand all slashes in filenames, so that a/bc is two errors  from  ab/c  (the  slash  cannot  be\ntransposed  with  another  character).  Similarly, errors are counted separately for non-con‐\ntiguous strings in the pattern, so that (ab|cd)ef is two errors from aebf.\n\nWhen using exclusion via the ~ operator, approximate matching is treated entirely  separately\nfor  the  excluded  part and must be activated separately.  Thus, (#a1)README~README matches\nREAD.ME but not README, as the trailing README is matched without approximation.   However,\n(#a1)README~(#a1)README does not match any pattern of the form READ?ME as all such forms are\nnow excluded.\n\nApart from exclusions, there is only one overall error count; however, the maximum errors al‐\nlowed  may  be  altered  locally,  and  this  can  be  delimited  by  grouping.  For example,\n(#a1)cat((#a0)dog)fox allows one error in total, which may not occur in the dog section,  and\nthe pattern (#a1)cat(#a0)dog(#a1)fox is equivalent.  Note that the point at which an error is\nfirst  found  is  the crucial one for establishing whether to use approximation; for example,\n(#a1)abc(#a0)xyz will not match abcdxyz, because the error occurs at the `x', where  approxi‐\nmation is turned off.\n\nEntire   path   segments   may  be  matched  approximately,  so  that  `(#a1)/foo/d/is/avail‐\nable/at/the/bar' allows one error in any path segment.  This  is  much  less  efficient  than\nwithout  the (#a1), however, since every directory in the path must be scanned for a possible\napproximate match.  It is best to place the (#a1) after any path segments which are known  to\nbe correct.\n"
                },
                {
                    "name": "Recursive Globbing",
                    "content": "A pathname component of the form `(foo/)#' matches a path consisting of zero or more directo‐\nries matching the pattern foo.\n\nAs a shorthand, `/' is equivalent to `(*/)#'; note that this therefore matches files in the\ncurrent directory as well as subdirectories.  Thus:\n\nls -ld -- (*/)#bar\n\nor\n\nls -ld -- /bar\n\ndoes a recursive directory search for files named `bar' (potentially including the file `bar'\nin  the  current  directory).  This form does not follow symbolic links; the alternative form\n`*/' does, but is otherwise identical.  Neither of these can be combined with  other  forms\nof  globbing  within  the  same path segment; in that case, the `*' operators revert to their\nusual effect.\n\nEven shorter forms are available when the option GLOBSTARSHORT is set.  In that case if  no\n/  immediately  follows  a    or  *  they are treated as if both a / plus a further * are\npresent.  Hence:\n\nsetopt GLOBSTARSHORT\nls -ld -- .c\n\nis equivalent to\n\nls -ld -- /*.c\n"
                },
                {
                    "name": "Glob Qualifiers",
                    "content": "Patterns used for filename generation may end in a list of qualifiers enclosed  in  parenthe‐\nses.   The  qualifiers specify which filenames that otherwise match the given pattern will be\ninserted in the argument list.\n\nIf the option BAREGLOBQUAL is set, then a trailing set of parentheses containing no `|'  or\n`(' characters (or `~' if it is special) is taken as a set of glob qualifiers.  A glob subex‐\npression  that  would normally be taken as glob qualifiers, for example `(^x)', can be forced\nto be treated as part of the glob pattern by doubling the parentheses, in this case producing\n`((^x))'.\n\nIf the option EXTENDEDGLOB is set, a different syntax  for  glob  qualifiers  is  available,\nnamely  `(#qx)'  where  x  is  any of the same glob qualifiers used in the other format.  The\nqualifiers must still appear at the end of the pattern.  However, with this  syntax  multiple\nglob qualifiers may be chained together.  They are treated as a logical AND of the individual\nsets  of  flags.   Also, as the syntax is unambiguous, the expression will be treated as glob\nqualifiers just as long any parentheses contained within it are balanced; appearance of  `|',\n`('  or `~' does not negate the effect.  Note that qualifiers will be recognised in this form\neven if a bare glob qualifier exists at the end of the pattern, for example `*(#q*)(.)'  will\nrecognise  executable  regular  files  if  both options are set; however, mixed syntax should\nprobably be avoided for the sake of clarity.  Note that within conditions using the `[[' form\nthe presence of a parenthesised expression (#q...) at the end  of  a  string  indicates  that\nglobbing  should  be  performed;  the  expression may include glob qualifiers, but it is also\nvalid if it is simply (#q).  This does not apply to the right hand side of pattern match  op‐\nerators as the syntax already has special significance.\n\nA qualifier may be any one of the following:\n\n/      directories\n\nF      `full'  (i.e.  non-empty)  directories.   Note that the opposite sense (^F) expands to\nempty directories and all non-directories.  Use (/^F) for empty directories.\n\n.      plain files\n\n@      symbolic links\n\n=      sockets\n\np      named pipes (FIFOs)\n\n*      executable plain files (0100 or 0010 or 0001)\n\n%      device files (character or block special)\n\n%b     block special files\n\n%c     character special files\n\nr      owner-readable files (0400)\n\nw      owner-writable files (0200)\n\nx      owner-executable files (0100)\n\nA      group-readable files (0040)\n\nI      group-writable files (0020)\n\nE      group-executable files (0010)\n\nR      world-readable files (0004)\n\nW      world-writable files (0002)\n\nX      world-executable files (0001)\n\ns      setuid files (04000)\n\nS      setgid files (02000)\n\nt      files with the sticky bit (01000)\n\nfspec  files with access rights matching spec. This spec may be  a  octal  number  optionally\npreceded by a `=', a `+', or a `-'. If none of these characters is given, the behavior\nis  the  same  as for `='. The octal number describes the mode bits to be expected, if\ncombined with a `=', the value given must match the file-modes exactly, with a `+', at\nleast the bits in the given number must be set in the file-modes, and with a `-',  the\nbits  in the number must not be set. Giving a `?' instead of a octal digit anywhere in\nthe number ensures that the corresponding bits in the file-modes are not checked, this\nis only useful in combination with `='.\n\nIf the qualifier `f' is followed by any other character anything up to the next match‐\ning character (`[', `{', and `<' match `]', `}', and `>' respectively, any other char‐\nacter matches itself) is taken as a list of comma-separated sub-specs.  Each  sub-spec\nmay  be  either  an octal number as described above or a list of any of the characters\n`u', `g', `o', and `a', followed by a `=', a `+', or a `-', followed by a list of  any\nof  the  characters  `r', `w', `x', `s', and `t', or an octal digit. The first list of\ncharacters specify which access rights are to be checked. If a `u' is given, those for\nthe owner of the file are used, if a `g' is given, those of the group are  checked,  a\n`o' means to test those of other users, and the `a' says to test all three groups. The\n`=', `+', and `-' again says how the modes are to be checked and have the same meaning\nas  described  for  the  first  form above. The second list of characters finally says\nwhich access rights are to be expected: `r' for read access, `w' for write access, `x'\nfor the right to execute the file (or to search a directory), `s' for the  setuid  and\nsetgid bits, and `t' for the sticky bit.\n\nThus,  `*(f70?)' gives the files for which the owner has read, write, and execute per‐\nmission, and for which other group members have no rights, independent of the  permis‐\nsions for other users. The pattern `*(f-100)' gives all files for which the owner does\nnot have execute permission, and `*(f:gu+w,o-rx:)' gives the files for which the owner\nand the other members of the group have at least write permission, and for which other\nusers don't have read or execute permission.\n\nestring\n+cmd   The  string will be executed as shell code.  The filename will be included in the list\nif and only if the code returns a zero status (usually the status  of  the  last  com‐\nmand).\n\nIn  the  first form, the first character after the `e' will be used as a separator and\nanything up to the next matching separator will be taken  as the string; `[', `{', and\n`<' match `]', `}', and `>', respectively, while any other character  matches  itself.\nNote  that expansions must be quoted in the string to prevent them from being expanded\nbefore globbing is done.  string is then executed as shell code.  The string  globqual\nis appended to the array zshevalcontext the duration of execution.\n\nDuring the execution of string the filename currently being tested is available in the\nparameter REPLY; the parameter may be altered to a string to be inserted into the list\ninstead  of  the original filename.  In addition, the parameter reply may be set to an\narray or a string, which overrides the value of REPLY.  If set to an array, the latter\nis inserted into the command line word by word.\n\nFor example, suppose a directory contains a single file `lonely'.  Then the expression\n`*(e:'reply=(${REPLY}{1,2})':)' will cause the words `lonely1' and `lonely2' to be in‐\nserted into the command line.  Note the quoting of string.\n\nThe form +cmd has the same effect, but no delimiters appear around cmd.  Instead,  cmd\nis  taken  as the longest sequence of characters following the + that are alphanumeric\nor underscore.  Typically cmd will be the name of a shell function that  contains  the\nappropriate test.  For example,\n\nnt() { [[ $REPLY -nt $NTREF ]] }\nNTREF=reffile\nls -ld -- *(+nt)\n\nlists all files in the directory that have been modified more recently than reffile.\n\nddev   files on the device dev\n\nl[-|+]ct\nfiles having a link count less than ct (-), greater than ct (+), or equal to ct\n\nU      files owned by the effective user ID\n\nG      files owned by the effective group ID\n\nuid    files  owned  by user ID id if that is a number.  Otherwise, id specifies a user name:\nthe character after the `u' will be taken as a separator and the string between it and\nthe next matching separator will be taken as a user  name.   The  starting  separators\n`[',  `{',  and  `<'  match  the final separators `]', `}', and `>', respectively; any\nother character matches itself.  The selected files are those owned by this user.  For\nexample, `u:foo:' or `u[foo]' selects files owned by user `foo'.\n\ngid    like uid but with group IDs or names\n\na[Mwhms][-|+]n\nfiles accessed exactly n days ago.  Files accessed within the last n days are selected\nusing a negative value for n (-n).  Files accessed more than n days ago  are  selected\nby  a positive n value (+n).  Optional unit specifiers `M', `w', `h', `m' or `s' (e.g.\n`ah5') cause the check to be performed with months (of 30 days), weeks, hours, minutes\nor seconds instead of days, respectively.  An explicit `d' for days is also allowed.\n\nAny fractional part of the difference between the access time and the current part  in\nthe  appropriate  units  is  ignored  in the comparison.  For instance, `echo *(ah-5)'\nwould echo files accessed within the last five hours, while `echo *(ah+5)' would  echo\nfiles  accessed  at  least six hours ago, as times strictly between five and six hours\nare treated as five hours.\n\nm[Mwhms][-|+]n\nlike the file access qualifier, except that it uses the file modification time.\n\nc[Mwhms][-|+]n\nlike the file access qualifier, except that it uses the file inode change time.\n\nL[+|-]n\nfiles less than n bytes (-), more than n bytes (+), or exactly n bytes in length.\n\nIf this flag is directly followed by a size specifier `k' (`K'),  `m'  (`M'),  or  `p'\n(`P')  (e.g.  `Lk-50') the check is performed with kilobytes, megabytes, or blocks (of\n512 bytes) instead.  (On some systems additional specifiers are  available  for  giga‐\nbytes,  `g'  or `G', and terabytes, `t' or `T'.) If a size specifier is used a file is\nregarded as \"exactly\" the size if the file size rounded up to the next unit  is  equal\nto  the  test  size.  Hence `*(Lm1)' matches files from 1 byte up to 1 Megabyte inclu‐\nsive.  Note also that the set of files \"less than\" the test size only  includes  files\nthat  would  not  match  the equality test; hence `*(Lm-1)' only matches files of zero\nsize.\n\n^      negates all qualifiers following it\n\n-      toggles between making the qualifiers work on symbolic links  (the  default)  and  the\nfiles they point to, if any; any symbolic link for whose target the `stat' system call\nfails (whatever the cause of the failure) is treated as a file in its own right\n\nM      sets the MARKDIRS option for the current pattern\n\nT      appends  a  trailing  qualifier mark to the filenames, analogous to the LISTTYPES op‐\ntion, for the current pattern (overrides M)\n\nN      sets the NULLGLOB option for the current pattern\n\nD      sets the GLOBDOTS option for the current pattern\n\nn      sets the NUMERICGLOBSORT option for the current pattern\n\nYn     enables short-circuit mode: the pattern will expand to at most n filenames.   If  more\nthan  n  matches  exist, only the first n matches in directory traversal order will be\nconsidered.\n\nImplies oN when no oc qualifier is used.\n\noc     specifies how the names of the files should be sorted. The following values of c  sort\nin the following ways:\n\nn      By name.\nL      By the size (length) of the files.\nl      By number of links.\na      By time of last access, youngest first.\nm      By time of last modification, youngest first.\nc      By time of last inode change, youngest first.\nd      By  directories: files in subdirectories appear before those in the current di‐\nrectory at each level of the search -- this is best combined with other  crite‐\nria, for example `odon' to sort on names for files within the same directory.\nN      No sorting is performed.\nestring\n+cmd   Sort by shell code (see below).\n\nNote  that  the  modifiers  ^  and  - are used, so `*(^-oL)' gives a list of all files\nsorted by file size in descending order, following any symbolic links.  Unless  oN  is\nused, multiple order specifiers may occur to resolve ties.\n\nThe  default sorting is n (by name) unless the Y glob qualifier is used, in which case\nit is N (unsorted).\n\noe and o+ are special cases; they are each followed by shell code,  delimited  as  for\nthe  e  glob qualifier and the + glob qualifier respectively (see above).  The code is\nexecuted for each matched file with the parameter REPLY set to the name of the file on\nentry and globsort appended to zshevalcontext.  The code should modify the parameter\nREPLY in some fashion.  On return, the value of the parameter is used instead  of  the\nfile  name as the string on which to sort.  Unlike other sort operators, oe and o+ may\nbe repeated, but note that the maximum number of sort operators of any kind  that  may\nappear in any glob expression is 12.\n\nOc     like  `o',  but  sorts  in  descending order; i.e. `*(^oc)' is the same as `*(Oc)' and\n`*(^Oc)' is the same as `*(oc)'; `Od' puts files in the current directory before those\nin subdirectories at each level of the search.\n\n[beg[,end]]\nspecifies which of the matched filenames should be included in the returned list.  The\nsyntax is the same as for array subscripts. beg and the optional end may be mathemati‐\ncal  expressions. As in parameter subscripting they may be negative to make them count\nfrom the last match backward. E.g.: `*(-OL[1,3])' gives a list of  the  names  of  the\nthree largest files.\n\nPstring\nThe  string will be prepended to each glob match as a separate word.  string is delim‐\nited in the same way as arguments to the e glob qualifier described above.  The quali‐\nfier can be repeated; the words are prepended separately so that the resulting command\nline contains the words in the same order they were given in the list of  glob  quali‐\nfiers.\n\nA  typical use for this is to prepend an option before all occurrences of a file name;\nfor example, the pattern `*(P:-f:)' produces the command line arguments `-f  file1  -f\nfile2 ...'\n\nIf  the  modifier  ^  is  active,  then  string will be appended instead of prepended.\nPrepending and appending is done independently so both can be used on  the  same  glob\nexpression;  for  example by writing `*(P:foo:^P:bar:^P:baz:)' which produces the com‐\nmand line arguments `foo baz file1 bar ...'\n\nMore than one of these lists can be combined, separated by commas. The whole list matches  if\nat  least  one  of  the sublists matches (they are `or'ed, the qualifiers in the sublists are\n`and'ed).  Some qualifiers, however, affect all matches generated, independent of the sublist\nin which they are given.  These are the qualifiers `M', `T', `N', `D', `n', `o', `O' and  the\nsubscripts given in brackets (`[...]').\n\nIf  a  `:' appears in a qualifier list, the remainder of the expression in parenthesis is in‐\nterpreted as a modifier (see the section `Modifiers' in  the  section  `History  Expansion').\nEach  modifier must be introduced by a separate `:'.  Note also that the result after modifi‐\ncation does not have to be an existing file.  The name of any existing file can  be  followed\nby  a  modifier  of the form `(:...)' even if no actual filename generation is performed, al‐\nthough note that the presence of the parentheses causes the entire expression to be subjected\nto any global pattern matching options such as NULLGLOB. Thus:\n\nls -ld -- *(-/)\n\nlists all directories and symbolic links that point to directories, and\n\nls -ld -- *(-@)\n\nlists all broken symbolic links, and\n\nls -ld -- *(%W)\n\nlists all world-writable device files in the current directory, and\n\nls -ld -- *(W,X)\n\nlists all files in the current directory that are world-writable or world-executable, and\n\nprint -rC1 /tmp/foo*(u0^@:t)\n\noutputs the basename of all root-owned files beginning with the string `foo' in /tmp,  ignor‐\ning symlinks, and\n\nls -ld -- *.*~(lex|parse).[ch](^D^l1)\n\nlists  all files having a link count of one whose names contain a dot (but not those starting\nwith a dot, since GLOBDOTS is explicitly switched off) except for lex.c, lex.h, parse.c  and\nparse.h.\n\nprint -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/)\n\ndemonstrates  how colon modifiers and other qualifiers may be chained together.  The ordinary\nqualifier `.' is applied first, then the colon modifiers in order from left to right.  So  if\nEXTENDEDGLOB  is  set  and  the base pattern matches the regular file builtin.pro, the shell\nwill print `shmiltin.shmo'.\n\nzsh 5.9                                     May 14, 2022                                  ZSHEXPN(1)"
                }
            ]
        }
    },
    "summary": "zshexpn - zsh expansion and substitution",
    "flags": [],
    "examples": [],
    "see_also": []
}