#!/bin/bash
str="a b --n d"
array=($str)
length=${#array[@]}
echo $length
for ((i=0; i$length; i++))
do
echo ${array[$i]}
done
#!/bin/bash
str2="a#b#c"
a=($(echo $str2 | tr '#' ' ' | tr -s ' '))
length=${#a[@]}
for ((i=0; i$length; i++))
do
echo ${a[$i]}
done
#echo ${a[2]}
#!/bin/bash
str="a b --n dd"
array=($str)
length=${#array[@]}
#ouput the first array element直接輸出的是數(shù)組的第一個元素
echo $array
#Use subscript way access array用下標的方式訪問數(shù)組元素
echo ${array[1]}
#Output the array輸出這個數(shù)組
echo ${array[@]}
#Output in the array subscript for 3 the length of the element輸出數(shù)組中下標為3的元素的長度
echo ${#array[3]}
#Output in the array subscript 1 to 3 element輸出數(shù)組中下標為1到3的元素
echo ${array[@]:1:3}
#Output in the array subscript greater than 2 elements輸出數(shù)組中下標大于2的元素
echo ${array[@]:2}
#Output in the array subscript less than 2 elements輸出數(shù)組中下標小于2的元素
echo ${array[@]::2}