Bash 脚本中的命令输出到下拉框?

发布于 2024-11-27 07:23:11 字数 510 浏览 1 评论 0原文

首先,我感谢回答这个问题的所有帮助。 我在 bash 脚本中有一个命令,它将输出以下内容:

255 254 253 252 ... 7 6 5 4 3 2 1 

它是一个特定的数字列表,从最大的数字开始(这就是我想要的),然后到最小的数字。数据集以空格分隔。如果您在 Linux 计算机上的终端中或通过 bash 脚本运行此命令,您将看到上面的输出(除了包括所有数字)。

我已将 apache2 服务器配置为允许通过 cgi-bin 目录使用 cgi/bash。当我在网络上的 bash 文件中运行此命令时,我得到了预期的输出。

我正在寻找一种方法,能够将这些数字作为一个单独的条目放入下拉框中进行选择,这意味着用户可以从下拉列表中选择一个数据点(例如 254)菜单。

我不确定我在做什么,所以任何帮助将不胜感激。我不确定是否需要将数据转换为数组,或者什么。下拉菜单可以位于 bash 脚本的同一页面上,但无论它在哪里,每次运行时都必须更新命令中的数字列表。

感谢您的帮助。

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 4 3 2 1 

It is a specific list of numbers, beginning with the largest (which is what I would like), then going to the smallest. The dataset is space-delimited. The output above (except including all numbers), is what you would see if you ran this command in the terminal on a linux machine, or through a bash script.

I have configured my apache2 server to allow for cgi/bash through the cgi-bin directory. When I run this command in a bash file from the web, I get the expected output.

What I'm looking for is for a way to be able to put these numbers each as a separate entry in a drop-down box for selection, meaning the user can select one point of data (254, for example) from the drop down menu.

I'm not sure what I'm doing with this, so any help would be appreciated. I'm not sure if I need to convert the data into an array, or what. The drop down menu can be on the same page of the bash script, but wherever it is, it has to update it's list of numbers from the command every time it is run.

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酷炫老祖宗 2024-12-04 07:23:11

我一直发现这个网站在摆弄 shell 脚本时很有用: http://tldp.org/LDP/ abs/html/

你必须使用某种字符串操作将输出放入数组中,使用空格作为分隔符,然后循环它以构建一些 html 输出 - 所以返回值基本上只会输出你的执行页面上的选择框你的cgi/bash脚本。

-肖恩

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

农村范ル 2024-12-04 07:23:11

重复答案(因为原始问题被标记为重复):

您可以编写一个 bash for 循环来完成所有操作。这只是打印出元素:

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

为了获得正确的对齐方式,您需要计算出最大长度(一个循环),然后打印出术语:

# 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"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文