3

I am looking for a way to create multiple files with one command and automate the process. They should share a common name but different extensions. The extensions are always the same.
For example index.js, index.css, index.html
So instead of using

touch index.js, index.css, index.html 

I would like to have an miracoules command which does something like this:

*miracle* index  

and 3 files are created.

11

Something like

touch index.{js,css,html}

should work. Which of course can then be turned into a shell function with

miracle() {
    [[ "$1" ]] && touch -- "$1."{js,css,html}
}

The test ensures that the files only get created if a name is passed as an argument, the touch -- ensures that miracle -foo doesn't lead to an error.

and used as

miracle index

To have this defined automatically in bash add the function definition to ~/.bash_profile, for zsh use ~/.zprofile.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .