Shell配列の使用と遍歴

463 ワード

Shellの配列の定義と遍歴、例:
 #!/bin/bash

#                
array=('a' 'b' 'c' 'd' 'e')

#       
arrayIndex[0]=1
arrayIndex[1]=2
arrayIndex[2]=3
arrayIndex[3]=4
arrayIndex[4]=5

#     
array[0]='f'
arrayIndex[1]=6

#      
echo ${#arrayIndex[@]}

#for     
for var in ${arrayIndex[@]}
do
  echo $var
done

#while     
i=0
while  [[ i -lt ${#arrayIndex[@]} ]];do
  echo ${arrayIndex[i]}
  let i++
done