Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re[2]: why not promote the plague ? (brace|rc|alternative|modern) syntax



On Sat, 14 Dec 2024 14:54:37 -0500 "Mark J. Reed" <markjreed@xxxxxxxxx> wrote:

MJR> Just to be perfectly clear, let me lay out all the options for compound
MJR> commands. Please correct me if I've gotten any of it wrong.
MJR> 
MJR> First, we have the standard syntax that works in any POSIX shell:
MJR> 
MJR>     for var in val1 val2 val3; do command1; command2; done
[...]
MJR> All of the above have an alternative syntax in Zsh that works irrespective
MJR> of the *SHORT_LOOPS* option, where you put the condition (if any) in
MJR> parentheses and the body in curly braces:
MJR> 
MJR>     for var (val1 val2 val3) { command1; command2; }
[...]
MJR> Finally, we have the Zsh "short" syntax, which works only with *setopt
MJR> SHORT_LOOPS*, and *only if the body is a single command*:
MJR> 
MJR>     for var (val1 val2 val3) command1;

 Thanks for the summary, it's really useful!

 But I think it would make sense to add that there is also the

	for var in val1 val2 val3; command

syntax which is not covered by any of the options above, but is an
alternative (or maybe even primary?) short loop syntax and the one which I,
personally, use the most often, as it seems more "shellish" to me than
using the parentheses, while still avoiding the do/done boilerplate for the
short loops I write on the command line.

 Regards,
VZ

Attachment: pgpdufgHkUr7t.pgp
Description: PGP signature



Messages sorted by: Reverse Date, Date, Thread, Author