Observe (note that I am testing with 5.3rc2, which is the latest version I have
access to ATM):
First, go to a terminal on $somehost and do: netcat -vv -lp $someport
then do:
~/Build/bash-5.3-rc2 $ ./bash ; echo "Bash has exited!"
$ echo $BASH_VERSION
5.3.0(1)-rc2
$ exec 3<>/dev/tcp/$somehost/$someport
Now, verify that two-way communication is working. When we write "hello" to
the TCP
pipe, it does show up on the netcat side. When we type something on the netcat
side,
we can read it here.
$ echo hello >&3
$ read -u3; echo $REPLY
This is a test
$ echo hello again >&3
At this point, I hit ^C on the netcat, causing it to exit, then do:
$ echo hello and again >&3
$ echo hello and again >&3
Status: 141
Bash has exited!
$
I find both of the following less than optimal:
1) That you have to do it twice to get it to exit (why twice?). This is
not a
fluke or a one-off; it seems to be consistent.
2) That the bash shell crashes and doesn't handle it gracefully.
Update: I realized while composing this that you probably need to trap SIGPIPE
in the
shell. So, I added:
$ trap 'echo OK;let trapped++' PIPE
$ echo hello >&3
bash: echo: write error: Broken pipe
bash: DEBUG warning: run_pending_traps: recursive invocation while running trap
for
signal 66
OK
Status: 1
$
Now, the DEBUG warning is no doubt caused by the fact that I have:
trap -- 'echo "Status: $?"' ERR
So, I removed that, and did the "echo hello >&3" again, and the DEBUG warning
goes
away, but the "bash: echo: write error: Broken pipe" remains.
Which is still less than optimal...
=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.
When responding to my posts, please try to refrain from giving bureaucratic
answers.
If you have nothing useful to say, then just click Next and go on.