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

随声附和 提交于 2019-12-02 10:57:17

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

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!