在bash中的元组上循环?

是否可以在bash中循环元组

作为一个例子,如果以下工作将是巨大的:

for (i,j) in ((c,3),(e,5)); do echo "$i and $j"; done

一个解决方法,不知何故让我循环的元组

$ for i in c,3 e,5; do IFS=","; set -- $i; echo $1 and $2; done
c and 3
e and 5

关于这个使用set(from man builtins):

Any arguments remaining after option processing are treated as values
for the positional parameters and are assigned,in order,to $1,$2,
… $n

IFS =“,”设置字段分隔符,因此每个$ i都被正确分段为$ 1和$ 2。

通过this blog

编辑:更正确的版本,如@SLACEDIAMOND建议:

$ OLDIFS=$IFS; IFS=','; for i in c,5; do set -- $i; echo $1 and $2; done; IFS=$OLDIFS
c and 3
e and 5

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...