[Shell]将字符串分隔进shell数组
2018-08-03 本文已影响8人
_小老虎_
例如有一段字符串:
bak1_list="a,b,c,d"
可以进行分隔:
OLD_IFS="$IFS"
IFS=","
arr=($bak1_list)
IFS="$OLD_IFS"
for val in ${arr[@]}
do
echo "$val"
done
输出:
a
b
c
d
例如有一段字符串:
bak1_list="a,b,c,d"
可以进行分隔:
OLD_IFS="$IFS"
IFS=","
arr=($bak1_list)
IFS="$OLD_IFS"
for val in ${arr[@]}
do
echo "$val"
done
输出:
a
b
c
d