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
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