Search code examples
shellzshglobexpansion

How to use zsh glob expansion to run same command multiple times?


I'm looking for the zsh syntax to run a single command multiple times with a range of parameters.

Instead of writing:

touch f_a
touch f_b
...
touch f_z

I'd like to execute:

touch f<a..z>

Solution

  • You can use:

    touch f{a..z}
    

    I think the name of the resource is curly brace expansion.

    You can also use leading zeros:

    echo file-{001..100}
    

    On zsh you can print one item for each line like this:

    printf '%s\n' {001..100}