Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 535 Bytes

use-arrays.md

File metadata and controls

21 lines (15 loc) · 535 Bytes

Use arrays in bash scripts

Bash supports single-dimension arrays. There are several ways to declare arrays, one such way is:

myarr=( zero one two three four )

# Index into arrays with this syntax
echo ${myarr[0]}

Loop over an array with a for loop:

for i in "${myarr[@]}"
do
   echo "$i"
done

Remember: Bash variables are untyped. Read more and see examples in the Advanced Bash Scripting Guide.