Break from the infinite loop

I execute this request in bash:

mkfifo resp
while true; do 
    sudo nc -l -p 80 < resp |
    (cat & echo -e "HTTP/1.1 200 OK\r\n\r\nhello :)" > resp) ||
    break; 
done

However, when I am Ctrl+C, nothing happens and the terminal is blocked.

Why? What am I doing wrong?

+5
source share
2 answers

I cannot recreate this in my environment (RHEL). CTRL-C works great for me. After your terminal closes, I will open a new one and use strace -pit to see what happens.

I think there are some problems with setting up the team as a whole.

First, you come to cata subshell. Doing this makes the stdincommandscat /dev/null , not the output nc, which you connect into a subshell. You can see the difference by comparing the output of this:

#! /bin/bash
# doesn't print yay
while true; do
    echo yay |
    (cat & false) ||
    break
done

with this:

#! /bin/bash
# does print yay
while true; do
    echo yay |
    (cat ; false) ||
    break
done

, , , , , , echo, , . , false echo:

#! /bin/bash
while true; do
    echo yay |
    (cat & echo test) ||
    break
done

, @chepner, nc . :

-l      Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host.  It is an error to use this option in conjunction with the -p, -s, or -z options.

, nc ( , ). , mkfifo resp ; nc -l -p 80 < resp root, echo -e "HTTP/1.1 200 OK\r\n\r\nhello :)" > resp root.

, .

+2

. sudo script script?

ctrl-Z ps a , ?

0

All Articles