方法1:用awk切分
-----------------------------------------------------
dbs="idigger,idiggersem,sony,mso"
dbarr=`echo $dbs | awk -F"," '{print $0}' | sed "s/,/ /g"`
for db in $dbarr
do
echo $db
done
---------------------------------------------------
运行结果如下:
$ sh awk_divide.sh
idigger
idiggersem
sony
mso
方法2:用shell切分
--------------------------------------------------
dbs="idigger,idiggersem,sony,mso"
dbarr=(${dbs//,/ }) #将字符串中,替换成空格
dbnum=${#dbarr[@]}
echo $dbnum
for db in ${dbarr[@]}
do
echo $db
done
-------------------------------------------------
运行结果如下:
$ sh shell_divide.sh
4
idigger
idiggersem
sony
mso