Added loops

This commit is contained in:
Dylan Araps
2018-06-15 16:43:03 +10:00
parent b162634394
commit f3a113f370

View File

@@ -596,10 +596,17 @@ done
## Loop over an array with an index. ## Loop over an array with an index.
```shell ```shell
arr=(apples oranges tomatoes)
# Elements and index. # Elements and index.
for i in "${!arr[@]}"; do for i in "${!arr[@]}"; do
printf '%s\n' "${arr[$i]}" printf '%s\n' "${arr[$i]}"
done done
# Alternative method.
for ((i=0;i<${#arr[@]};i++)); do
printf '%s\n' "${arr[$i]}"
done
``` ```
## Loop over the contents of a file. ## Loop over the contents of a file.