Created
April 12, 2022 14:47
-
-
Save goddoe/ac8e39f0c3e992af00897577bdd4f54b to your computer and use it in GitHub Desktop.
bash for loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Reference: https://blog.leocat.kr/notes/2018/02/17/shell-looping-list | |
| $ cat test.sh | |
| #!/bin/bash | |
| for NAME in "ME" "YOU" "THEM" "ALL"; do | |
| echo "Name is ${NAME}" | |
| done | |
| PLANETS=( "EARTH" "MARS" "VINUS" ) | |
| for PLANET in ${PLANETS[@]}; do | |
| echo "This is ${PLANET}" | |
| done | |
| for (( i=0; i<${#PLANETS[@]}; i++ )); do | |
| echo "Planet #$i is ${PLANETS[i]}" | |
| done | |
| $ ./test.sh | |
| Name is ME | |
| Name is YOU | |
| Name is THEM | |
| Name is ALL | |
| This is EARTH | |
| This is MARS | |
| This is VINUS | |
| Planet #0 is EARTH | |
| Planet #1 is MARS | |
| Planet #2 is VINUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment