Ubuntu: How to loop through arguments in Bash ($1 $2 $3 and so forth)?



Question:

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???


Solution:1

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »