在bash中完全同时运行两个命令

时间:2018-10-04 10:38:50

标签: bash

代码:

#!/bin/bash
nc ipv4 port echo "hi"

问题: 在连接到侦听器后,我如何自动说“嗨”?

1 个答案:

答案 0 :(得分:0)

如果要在命令后保持连接打开,可以使用fifo

mkfifo fifo_filename

# start nc reading from fifo in background (jobs,kill can be used to monitor)
nc host port <fifo_filename &

# open file descriptor 3 to write to fifo
exec 3>fifo_filename 
echo hi >&3
...
echo bye >&3

# close file descriptor (will close the fifo and background nc will exit)
exec 3>&-
相关问题