@nrailgun
2016-06-22T14:52:46.000000Z
字数 562
阅读 1307
程序设计
Array: An array is a numbered list of strings: it maps integers to strings.
With =()
syntax.
names=("John" "$USER")
Glob can also be used.
files=(~/*'.jpg')
Do not use
l=$(ls)
l=($(ls))
Use
l=(*)
echo ${#array[@]}
We can use a for loop to iterate over the elements
for i in "${l[@]}"; do
echo "$i"
done
We use the quoted form again here: "${l[@]}"
. Bash replaces this syntax with each element in the array properly quoted.
Use "${!l[@]}"
to loop over the indices of arrays.
for i in "${!l[@]}"; do
echo "${l[i]}"
done
Since it works with sparse array, it better than ${#l[@]}
.