Writing shell script to print a certain number of lines with certain arguments

前端 未结 3 1915
傲寒
傲寒 2021-01-28 15:09

I have 5 variables and each variables contains five values.I want to print five lines with the five values from five variables one by one For example

$a=1 2 3 4          


        
3条回答
  •  无人及你
    2021-01-28 15:47

    If you transpose the matrix, this is really simple, portable, and idiomatic.

    while read -r a b c d e; do
        : stuff with "$a", "$b", etc
    done <<____
        1 4 8 8 5
        2 2 9 7 6
        3 3 7 6 7
        4 4 6 5 3
        5 5 5 4 3
    ____
    

    Notice how the first column enumerates the a values, the second, the bs, etc.

提交回复
热议问题