<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Ron,</p>
    <p>This is my complaint. It looks like bash code, but it doesn't
      run. I followed the instructions, made it executable, and then
      tried to run, and I get this:</p>
    <pre>$ ./bash_web.sh 
./bash_web.sh: line 6: HTTP: command not found
./bash_web.sh: line 9: syntax error near unexpected token `)'
./bash_web.sh: line 9: `'{print $1}') path=$(echo "$request" | awk '{print $2}')'

OK, so the script is a little munged from the copy and paste. So I spend 15 minute cleaning that up and I get this:

$ curl localhost:8080/
curl: (52) Empty reply from server

So I stand by what I said, AI isn't good at bash programming. You want a job that won't fall prey to AI, use bash ;-)

Craig....
</pre>
    <div class="moz-cite-prefix">On 3/2/24 12:23, Ron / BCLUG wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:a6e81b4e-3cbf-43d2-a3b4-bb2708693479@bclug.ca">#!/bin/bash
      <br>
      <br>
      # Define the port on which the server will listen PORT=8080
      <br>
      <br>
      # Function to handle incoming requests handle_request() { # Read
      the
      <br>
      HTTP request from the client read -r request
      <br>
      <br>
      # Extract the request method and path method=$(echo "$request" |
      awk
      <br>
      '{print $1}') path=$(echo "$request" | awk '{print $2}')
      <br>
      <br>
      # Serve a simple response if [ "$method" = "GET" ]; then if [
      "$path"
      <br>
      = "/" ]; then echo -e "HTTP/1.1 200 OK\r\nContent-Type:
      <br>
      text/html\r\n\r\n<html><body><h1>Hello,
      World!</h1></body></html>" else echo -e
      "HTTP/1.1 404 Not Found\r\nContent-Type:
      <br>
      text/plain\r\n\r\n404 Not Found" fi else echo -e "HTTP/1.1 501 Not
      <br>
      Implemented\r\nContent-Type: text/plain\r\n\r\n501 Not
      Implemented" fi }
      <br>
      <br>
      # Main loop to listen for incoming connections main() { echo
      <br>
      "Starting server on port $PORT..." mkfifo fifo trap "rm -f fifo"
      <br>
      EXIT
      <br>
      <br>
      # Continuously listen for connections while true; do # Wait for a
      <br>
      client to connect cat fifo | nc -l -p "$PORT" >
      >(handle_request) done }
      <br>
      <br>
      main
    </blockquote>
    <div class="moz-signature">-- <br>
      IPv6 is the future, the future is here<br>
      <a href="ipv6hawaii.org" class="moz-txt-link-freetext">ipv6hawaii.org</a></div>
  </body>
</html>