Shell数组遍历

#!/bin/bash

emp_info=(
aaa 13800000000 [email protected]
bbb 13800000001 [email protected]
ccc 13800000002 [email protected]
ddd 13800000003 [email protected]
eee 13800000004 [email protected]
)

for i in ${!emp_info[@]}
do
    if [ `expr $i % 3` = "2" ] # get mail addr
    then
        name=${emp_info[`expr $i - 2`]}
        mailaddr=${emp_info[$i]}
        mobile=${emp_info[`expr $i - 1`]}
        echo $name $mobile $mailaddr
    fi
done

 

你可能感兴趣的:(Shell数组遍历)