How to merge two arrays in a zipper like fashion in Bash?

后端 未结 5 1831
野趣味
野趣味 2020-11-29 13:23

I am trying to merge two arrays into one in a zipper like fashion. I have difficulty to make that happen.

array1=(one three five seven)
array2=(two four six          


        
5条回答
  •  自闭症患者
    2020-11-29 13:57

    I've found more common the case where I want to zip two arrays into two columns. This isn't as natively Zsh as the "RTLinuxSW" answer, but for this case, I use paste.

    % tabs 16
    % paste <(print -l $array1) <(print -l $array2)
    one     two
    three   four
    five    six
    seven   eight
    

    And then can shove that into another array to get the intended output:

    % array3=( `!!`«tab»«tab» )
    % print $array3
    one two three four five six seven eight
    

提交回复
热议问题