CGI bash / html:如何用bash脚本填充列表框

时间:2019-04-11 12:13:21

标签: bash shell

我需要在bash / html中开发一个CGI。我想创建一个列表框,它将使用文本文件自动填充。

我尝试这个:

#!/bin/bash

echo "Content-type: text/html"
echo ""

echo "
<html>
<head>
        <title> CLUSTER GRAPH </title>
        <h1> Cluster Graph </h1>
<hr size="4" color="blue" >

</head>
<body>

<PRE>"

declare -A array

array=$(cat CLUSTER_1.txt | awk -F',' '{print $1}')

echo $row

echo "<FORM>
    <SELECT onChange=
      "document.location=this.options[this.selectedIndex].value">
      <OPTION VALUE="#" SELECTED>     DAY     </OPTION>
      <OPTION VALUE="111.html"> $array </SELECT>
  </FORM> "



echo "

</PRE>

</body>
</html>
"

但是结果是:

enter image description here

我需要...这:

enter image description here

我认为我必须使用for循环,但我不知道如何。你能告诉我吗?

1 个答案:

答案 0 :(得分:0)

尝试一下:

array=$(cat CLUSTER_1.txt | awk -F',' '{print $1}')
echo "<FORM><SELECT onChange='document.location=this.options[this.selectedIndex].value'>"
echo "<OPTION VALUE='#' SELECTED>     DAY     </OPTION>"
echo "$array" | while read WHILEDATE; do
      echo "<OPTION VALUE='111.html'>" $WHILEDATE "</SELECT>"
done
echo "</FORM>"