That I know.for i (2 1) echo $i
Deep and powerful, but tricky as you explain.
To concatenate all the non-hidden files in the current working
directory, [o]rdered by [L]ength:
set -o extendedglob
cat ./^output(-.oL) > output
Funny, as much as I can forget basic things over and over again, I always know when I'm seeing something for the first time. So we can plug in a command substitution where I'd have never used anything but a wildcard or itemized list '(1 2 3)'. Predictable now that I see it. And more transparent than Stephane's way tho not as fundamental.* expands to the files sorted lexically by name under your current locale settings. If you want to sort them elsewise, you have to use something besides a wildcard. Easiest is probably to ask ls for them in the order you want; -t sorts by date, defaulting to newest first; adding -r switches to oldest first:
by_date=(${(f)"$(ls -1tr)"})
for aa in $by_date; do
Cool. One of those things that's not apparent running it, but still, good to know.FWIW, in your example code, it's more efficient if you redirect the entire loop instead of doing individual appends per-file:
for aa in whatever; do cat $aa; done >>$output
Yeah I know that cat can do it by itself, but I thought the loop would get me closer to the levers of sortation control. Cool if not needed and I see the substitution can be used there as well so that's the way. And I see that I should have seen that.and if you're really doing cat, you don't need the loop at all.
cat $by_date >>$output
Nevermind! ;-)
But all of the above mechanisms including the for loop expand all the filenames into a single shell command line, and so have limits on how big that expanded list can be.