I'd like to write a simple web server uniquely in bash. Thus I go:
#!/usr/bin/env bash
exec 3<> <(nc -lp 8000)
echo "before the loop"
INDEX="<!DOCTYPE html><html><head><meta charset=\"UTF-8\"></head><body><p>QWERTY</p></body></html>"
while read -u 3 line; do
echo "line: ${line}" #why can one not encapsulate ${line} in single quotes, for one thing ?
xxd -pr <<<"$line"
if [[ "$line" == "\r\n" ]]; then
echo -en "HTTP/1.1 OK\r\nContent-Type: text/html\r\nContent-Length: $(wc -c <<<"${INDEX}" )\r\n\r\n${INDEX}" >&3
echo "printed"
sleep 1
fi
done
echo "efter the loop, line '${line}'"
exec 3>&-
but it does not work for me. Supposedly, since I've opened the pipe wrongly, but how to do it properly?