假设我有一个 Unix shell 变量,如下所示
variable=abc,def,ghij
我想使用 for 循环提取所有值(abc
、def
和 ghij
),并将每个值传递到过程中。
该脚本应允许从 $variable
中提取任意数量的逗号分隔值。
最佳答案
不要搞乱 IFS
不调用外部命令
variable=abc,def,ghij
for i in ${variable//,/ }
do
# call your procedure/other scripts here below
echo "$i"
done
使用 bash 字符串操作 http://www.tldp.org/LDP/abs/html/string-manipulation.html
关于shell - 循环遍历以逗号分隔的 shell 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27702452/