shell string转为数组
代码如下
$ cat str2arr.sh
#!/bin/bash
str="i,like,you,csdn"
arr=(${str//,/ })
for s in ${arr[@]}
do
echo $s
done
执行结果
$ sh str2arr.sh
i
like
you
csdn
$ cat str2arr.sh
#!/bin/bash
str="i,like,you,csdn"
arr=(${str//,/ })
for s in ${arr[@]}
do
echo $s
done
$ sh str2arr.sh
i
like
you
csdn