bash - 在 bash 中同时运行两个命令
问题描述
代码:
#!/bin/bash
nc ipv4 port echo "hi"
问题:如何让它在连接到听者后立即自动说 Hi?
解决方案
如果您想在命令后保持连接打开,可以使用 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>&-
推荐阅读
- java - spring事务超时可配置
- mysql - 如何查找相似的数据库查询
- css - 为什么我的字体大小百分比在 CSS 中不起作用?
- python - 为什么 pylint 在函数之外需要大写的变量名?
- node.js - 根据从基于 pug 的快速路由传入的 ID 更新特定的 MongoDB 文档
- scala - 给定方法参数返回最具体的类型
- r - 提升曲线被交换
- javascript - 鼠标滚轮上的 JS scrollIntoView 功能不起作用
- apache-beam-io - 使用 AWS S3 作为数据源的 TensorFlow 转换 Python
- php - 可捕获的致命错误:类 mysqli_stmt 的对象无法转换为字符串 3