I have a simple script which reads some lines from a connection initialized using netcat. A client can transmit some "commands". If the client write "exit" I like to close the connection.
BUT: After transmit the "exit" the script echos the "Received 'exit'" but still reads one more line before the "Good bye" appears.
echo "Start listening on port $PORT ..." (echo "Welcome. Please give me one of the following commands: $AVAILABLECOMMANDS") | nc -q -1 -l $PORT | while read line do if [ "$line" == 'exit' ]; then echo "Received 'exit'" break else result=$(executeCommand $line) echo "$result" fi done echo "Good bye"
I think I have to rewrite the loop but I have no idea how.
Can somebody help?