---
# System prepended metadata

title: Bash - for loop usage
tags: [bash]

---

# Bash - for loop usage

###### tags: `bash`

```
ubuntu@ip-172-31-29-119:/tmp$ names=( Jennifer Tonya Anna Sadie )

ubuntu@ip-172-31-29-119:/tmp$ for name in ${names[@]}; do echo $name; done
Jennifer
Tonya
Anna
Sadie

ubuntu@ip-172-31-29-119:/tmp$ for (( i = 0 ; i < ${#names[@]} ; i++ )) do echo ${names[$i]} ; done
Jennifer
Tonya
Anna
Sadie

root@ycheng:~# i=0; while [ ${i} -lt ${#names[@]} ]; do echo ${names[$i]}; ((i++)) ; done
Jennifer
Tonya
Anna
Sadie
```