#!/bin/bash string="hello,shell,haha" array=(${string//,/ }) for var in ${array[@]} do echo $var done
其中,// 和 /之间的分隔符,而且 / 后面有个空格
#!/bin/bash string="hello,shell,haha" OLD_IFS="$IFS" IFS="," array=($string) IFS="$OLD_IFS" for var in ${array[@]} do echo $var done