I have the following code snippet
for num do echo $num done
But I don't understand why it works! How come does Bash know to loop through my params $1, $2, $3, $... using my personal taste of "num" variable???
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
It's a feature of bash:
for num; do ...
is a shorthand for
for num in "$@"; do ...
The documentation is at http://www.gnu.org/software/bash/manual/bashref.html#Looping-Constructs