shell 脚本如下:
- #!/bin/sh
- #filename useshellarray
- #date: 2008-12-01 11:16:35
- count=0
- record="abc#def#ghi"
- `awk 'BEGIN { split("'"$record"'",myarray,"#")}
- END { for (i in myarray) {print myarray[i];$count++; }}' /dev/null > 2`
- while read buf
- do
- tArray[$c]=$buf
- c=$(expr $c + 1)
- done < 2
- echo "Array Length:" $c
- for((i=0;i<$c;i++));
- do
- echo ${tArray[$i]}
- done
执行这个脚本得到的结果为:
Array Length: 3
abc
def
ghi