Loop over tuples in bash?

后端 未结 12 1508
说谎
说谎 2020-12-04 21:00

Is it possible to loop over tuples in bash?

As an example, it would be great if the following worked:

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


        
12条回答
  •  眼角桃花
    2020-12-04 21:21

    A bit more involved, but may be useful:

    a='((c,3), (e,5))'
    IFS='()'; for t in $a; do [ -n "$t" ] && { IFS=','; set -- $t; [ -n "$1" ] && echo i=$1 j=$2; }; done
    

提交回复
热议问题