linux shell 将字符串分割成数组

 
 
a="one,two,three,four"

要将$a分割开,可以这样:

OLD_IFS="$IFS" 
IFS="," 
arr=($a) 
IFS="$OLD_IFS" 
for s in ${arr[@]} 
do 
    echo "$s" 
done

上述代码会输出

one 
two 
three 
four

猜你喜欢

转载自blog.csdn.net/zhuchunyan_aijia/article/details/80818839