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

前端 未结 2 686
青春惊慌失措
青春惊慌失措 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"
    
    0 讨论(0)
  • 2021-01-28 03:59

    I've always found this site useful when fiddling with shell scripts: http://tldp.org/LDP/abs/html/

    you'll have to get your output into an array using some sort of string manipulation using the spaces as delimiters, then loop over that to build some html output - so the return value will basically just output your select box on the page where you execute your cgi/bash script.

    -sean

    0 讨论(0)
提交回复
热议问题