1. dash的写法:
使用awk
string="abc,def,h"
for var in $(echo ${string} | awk '{split($0,arr,",");for(i in arr) print arr[i]}')
do
echo ${var}
done
2. bash可以这样写:
string="abc,def,h"
OLD_IFS=”$IFS”
IFS=”,”
arr=(${string})
IFS=”$OLD_IFS”
for var in ${arr[@]}
do
echo ${var}
done
或
string="abc,def,h"
arr=(${string//,/ })
for var in ${arr[@]}
do
echo ${var}
done
以上方法输出都为:
abc
def
h
来源:CSDN
作者:小时hour
链接:https://blog.csdn.net/c753575/article/details/104196869