简体   繁体   中英

CGI bash/html : how to fill a list box with bash script

I need to develop a CGI in bash/html. I want to create a list box which would be filled automaticaly in using a text file.

I try this :

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

But the result is :

在此处输入图片说明

And I need... This :

在此处输入图片说明

I think I must use a for loop but I don't know how. Can you show me ?

Try it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM