shell数组的使用

B shell

#!/bin/bash
#set -x
IFS="|"
str=`A|B|C`
array=($str)
length=${#array[@]}

echo $length
for (( i=0; i<$length; i++ ))
do
        echo ${array[$i]}
done


K shell


#!/bin/ksh
#set -x
IFS="|"
str=`A|B|C`
set -A array ${str}
length=${#array[@]}

echo $length
echo "++"
echo ${array[0]}
echo ${array[1]}
echo ${array[2]}
echo "++"
for i in ${array[*]}
do
        echo $i
done

你可能感兴趣的:(shell)