Output of command in Bash script to Drop-down box?

前端 未结 2 685
青春惊慌失措
青春惊慌失措 2021-01-28 03:03

First off, I appreciate any and all help in answering this question. I have a command in a bash script that will output the following:

255 254 253 252 ... 7 6 5          


        
2条回答
  •  一生所求
    2021-01-28 03:56

    Repeating the answer (since the original question was marked as duplicate):

    you can write a bash for loop to do everything. This just prints out the elements:

    for i in `seq 1 "${#x[*]}"`; do
        echo "|${x[i]} |"
    done
    

    To get the alignment correct, you need to figure out the max length (one loop) and then print out the terms:

    # w will be the length
    w=0
    for i in `seq 1 "${#x[*]}"`; do
        if [ $w -lt ${#x[$i]} ]; then w=${#x[$i]}; fi
    done
    for i in `seq 1 $((w+2))`; do printf "%s" "-"; done
    printf "\n"
    for i in `seq 1 "${#x[*]}"`; do
        printf "|%-$ws |\n" ${#x[$i]}
    done
    for i in `seq 1 $((w+2))`; do printf "%s" "-"; done
    printf "\n"
    

提交回复
热议问题