我需要在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>
"
但是结果是:
我需要...这:
我认为我必须使用for循环,但我不知道如何。你能告诉我吗?
答案 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>"