Trying to understand how the <&3 redirect can be caught into a var in bash.
When I run the code below it stops at line 9 with the MSG to SEND
being printed as if the cat <&3
is being run without catching it in the var myRcvMsg
. If I open another shell and nc on the port it continues to printout each line sent (this is what I want, just need to trap it rather than print it)
If I change line to myRcvMsg="$(<&3)"
then lines 10,11 execute but no var prints out.
what am I doing wrong?
thx Art
#!/bin/bash
echo "Starting Script"
exec nc -p 18000 -l &
sleep 1 # wait for port to open
exec 3<>/dev/tcp/192.168.1.1/18000
echo "MSG to SEND" >&3
echo "MSG has been sent"
myRcvMsg="$(cat <&3)"
echo "MSG should have been RCV'd"
echo "This is the RCV msg:${myRcvMsg}"