July 2018
Beginner
264 pages
8h 9m
English
The for loop is usually used when you have multiple tasks or commands to execute for each of the entries in an array or want to execute a given command on a finite number of items. In this example, we have an array (or list) containing three elements: file1, file2, and file3. The for loop will echo each element within FILES and exit the script:
#!/bin/bashFILES=( "file1" "file2" "file3" )for ELEMENT in ${FILES[@]}do echo "${ELEMENT}"doneecho "Echo\'d all the files"
Read now
Unlock full access