#!/bin/bash
rm out
mkfifo out
nc -l 8080 < out | while read line
do
echo hello > out
echo $line
done
If I browse to the IP of the machine this script is running on (using port 8080), I would expect to see the word 'hello' and then on the machine running the script, I would expect it to output lines from the request.
However, nothing happens. The browser gets no response, and nothing is output to the server's terminal.
Why doesn't it work, and what can I modify to make it work? I want to keep it to simple pipes, I don't want to use process substitution or anything like that.
echo
doesn't happen until afternc
reads something.while
loop by itself and it will hang waiting for input. Yournc -l 8080 < out
line isn't producing any input when it is piped to thiswhile
loop which is why it doesn't do anything. It is waiting for input which never arrives.