Simone Web Design

Loop through parameters in Bash

Iterating over the arguments in a Bash script is way simpler than you might expect.
See this gist:

In the snippet above, "$@" represents all the parameters. The echo "$i" shall obviously print each argument on a separate line.

It’s always a good idea to wrap parameters within quotes, because you’d never know when a parameter might contain spaces or whatever.

I hope you liked this blog post. If you'd like to get an alert when I publish the next one, you can subscribe via email below, or via RSS.