Can I execute the command for each result of the file globbing in zsh without for? Can I execute the command for each result of the file globbing in zsh without for? shell shell

Can I execute the command for each result of the file globbing in zsh without for?


You may be looking for zargs, a command with the same purpose as xargs but a saner interface.

autoload -U zargszargs -n 1 -- * -- mycommand


The printf command will implicitly loop if given more arguments than placeholders in the format string:

printf -- "--- %s\n"  [a-c]*

To execute a command on each file, you need xargs: I assume you have GNU xargs that has the -0 option:

printf "%s\0" [a-c]* | xargs -0 -I FILE echo aa FILE bb

Replace the echo xargs command with whatever you need, using the "FILE" placeholder where you need the filename.

Use your own judgement to determine if this is actually better or more maintainable than a for-loop.