René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
for loops in shells | ||
for n in foo bar baz; do echo $n; done for n in un dos tres; do echo $n done for n in a b c do echo $n done Iterating over $@
Consider the following script. In absence of a in, the for command iterates over $@:
iterate.sh
#!/bin/sh for i do echo $i done
If this script is called like so:
./iterate.sh one two three
the output will be:
one two three |