shell - 字符串切分成数组

shell字符串切分

#!/bin/bash
str="hello,world";
//与/之间与分割的字符 ,另外/后有一个空格不可省略
str=${str//,/ };
arr=($str);
#遍历数组
for element in ${arr[*]}
do
 echo $element
done

猜你喜欢

转载自blog.csdn.net/qq_29573903/article/details/89366427