June 2017
Beginner
502 pages
11h 26m
English
The for loop is one of the most used structures when it comes to a Bash script and enables us to repeat one of more actions on each single item in a list. Its basic structure can be outlined as follows:
for placeholder in list_of_itemsdo action_1 $placeholder action_2 $placeholder action_n $placeholderdone
So, we use a placeholder, which will take at each round of the loop one of the values in the list of items, which will then be processed in the do section. Once all the list is scanned through, the loop is done, and we exit it. Let's start with a simple and nice example:
#!/bin/bashfor i in 1 2 3 4 5do echo "$i"done
And now let's execute it:
zarrelli:~$ ./counter-simple.sh 12345
Actually, quite straightforward, but notice that ...
Read now
Unlock full access