美文网首页
shell 将字符串分割成数组

shell 将字符串分割成数组

作者: 夜空最亮的9星 | 来源:发表于2018-08-09 10:44 被阅读363次

    原文链接

    #!/bin/bash
    a="one,two,three,four"
    #要将$a分割开,可以这样:
    OLD_IFS="$IFS"
    IFS=","
    arr=($a)
    IFS="$OLD_IFS"
    for s in ${arr[@]}
    do
        echo "$s" 
    done
    

    相关文章

      网友评论

          本文标题:shell 将字符串分割成数组

          本文链接:https://www.haomeiwen.com/subject/dsjqbftx.html