【发布时间】:2014-01-05 03:17:38
【问题描述】:
试图了解如何将
当我运行下面的代码时,它在第 9 行停止,并打印了 MSG to SEND,就好像 cat <&3 正在运行,但没有在 var myRcvMsg 中捕获它。如果我在端口上打开另一个 shell 和 nc,它会继续打印发送的每一行(这就是我想要的,只需要捕获它而不是打印它)
如果我将行更改为myRcvMsg="$(<&3)",则执行第 10,11 行,但不会打印出任何 var。
我做错了什么?
谢谢 艺术
#!/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}"
【问题讨论】:
-
为什么你使用
cat程序而不是readshell 内置?