方法一
#!/bin/bash
string="php,java,python,shell,c++,c"
#将,替换为空格
array=(${string//,/ })
for var in ${array[@]}
do
echo $var
done
方法二
#!/bin/bash
string="php,java,python,shell,c++,c"
array=(`echo $string | tr ',' ' '` )
for var in ${array[@]}
do
echo $var
done
方法三
#!/bin/bash
string="php,java,python,shell,c++,c"
#对IFS变量 进行替换处理
OLD_IFS="$IFS"
IFS=","
array=($string)
IFS="$OLD_IFS"
for var in ${array[@]}
do
echo $var
done