Loop through a comma-separated shell variable

前端 未结 8 1953
醉话见心
醉话见心 2020-12-22 18:15

Suppose I have a Unix shell variable as below

variable=abc,def,ghij

I want to extract all the values (abc, def an

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-22 19:07

    Not messing with IFS
    Not calling external command

    variable=abc,def,ghij
    for i in ${variable//,/ }
    do
        # call your procedure/other scripts here below
        echo "$i"
    done
    

    Using bash string manipulation http://www.tldp.org/LDP/abs/html/string-manipulation.html

提交回复
热议问题