Added loops
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user