Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Documentation of colon in parameter expansion
- X-seq: zsh-users 11366
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Documentation of colon in parameter expansion
- Date: Sun, 01 Apr 2007 10:53:59 -0700
- In-reply-to: <loom.20070331T224203-896@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <loom.20070331T224203-896@xxxxxxxxxxxxxx>
(Hmm, posting a patch on April Fools' Day might not be the best idea.
Oh, well.)
On Mar 31, 8:51pm, Miciah Dashiel Butler Masters wrote:
}
} I was recently trying to look up the syntax for '${NAME-WORD}'.
} A search for '${NAME:-WORD}' turns up information on that syntax,
} but one must look several paragraphs down to see that '${NAME-WORD}'
} is also allowed and has a distinct meaning.
Suggested patch below. Line numbers may be off. Is the new final
paragraph ("In any of the above ...") incorrect in some way? It used
to only be stated for :- and :+ but I think it applies to := as well.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Doc/Zsh/expn.yo,v
retrieving revision 1.22
diff -c -r1.22 expn.yo
--- expn.yo 1 Oct 2006 02:38:52 -0000 1.22
+++ expn.yo 1 Apr 2007 17:31:29 -0000
@@ -450,39 +486,39 @@
If var(name) is the name of a set parameter `tt(1)' is substituted,
otherwise `tt(0)' is substituted.
)
+xitem(tt(${)var(name)tt(-)var(word)tt(}))
item(tt(${)var(name)tt(:-)var(word)tt(}))(
-If var(name) is set and is non-null then substitute its
-value; otherwise substitute var(word). If var(name) is
-missing, substitute var(word).
-Note that you can use standard shell quoting in the var(word) value to
-selectively override the splitting done by the tt(SH_WORD_SPLIT) option
-and the tt(=) flag, but not the tt(s:)var(string)tt(:) flag.
+If var(name) is set, or in the second form is non-null, then substitute
+its value; otherwise substitute var(word). In the second form var(name)
+may be omitted, in which case var(word) is always substituted.
)
+xitem(tt(${)var(name)tt(PLUS())var(word)tt(}))
+item(tt(${)var(name)tt(:PLUS())var(word)tt(}))(
+If var(name) is set, or in the second form is non-null, then substitute
+var(word); otherwise substitute nothing.
+)
+xitem(tt(${)var(name)tt(=)var(word)tt(}))
xitem(tt(${)var(name)tt(:=)var(word)tt(}))
item(tt(${)var(name)tt(::=)var(word)tt(}))(
-In the first form, if var(name) is unset or is null then
-set it to var(word); in the second form, unconditionally
-set var(name) to var(word). In both forms, the value of
-the parameter is then substituted.
+In the first form, if var(name) is unset then set it to var(word); in the
+second form, if var(name) is unset or null then set it to var(word); and
+in the third form, unconditionally set var(name) to var(word). In all
+forms, the value of the parameter is then substituted.
)
+xitem(tt(${)var(name)tt(?)var(word)tt(}))
item(tt(${)var(name)tt(:?)var(word)tt(}))(
-If var(name) is set and is non-null then substitute
-its value; otherwise, print var(word) and exit from the shell.
-Interactive shells instead return to the prompt.
-If var(word) is omitted, then a standard message is printed.
-)
-item(tt(${)var(name)tt(:PLUS())var(word)tt(}))(
-If var(name) is set and is non-null then substitute
-var(word); otherwise substitute nothing.
-Note that you can use standard shell quoting in the var(word) value to
-selectively override the splitting done by the tt(SH_WORD_SPLIT) option
-and the tt(=) flag, but not the tt(s:)var(string)tt(:) flag.
+In the first form, if var(name) is set, or in the second form if var(name)
+is both set and non-null, then substitute its value; otherwise, print
+var(word) and exit from the shell. Interactive shells instead return to
+the prompt. If var(word) is omitted, then a standard message is printed.
)
enditem()
-If the colon is omitted from one of the above expressions
-containing a colon, then the shell only checks whether
-var(name) is set, not whether its value is null.
+In any of the above expressions that test a variable and substitute an
+alternate var(word), note that you can use standard shell quoting in the
+var(word) value to selectively override the splitting done by the
+tt(SH_WORD_SPLIT) option and the tt(=) flag, but not splitting by the
+tt(s:)var(string)tt(:) flag.
In the following expressions, when var(name) is an array and
the substitution is not quoted, or if the `tt((@))' flag or the
Messages sorted by:
Reverse Date,
Date,
Thread,
Author