![](/img/trans.png)
[英]How to combine a echo/print command with another command such as cat or sed
[英]Combine echo and file as input to a command
我正在测试某种上传协议,并希望在一行中同时将输入参数作为回显,并将文件作为上传信息进行发送。
例:
echo -e 'upload\n<uploadid>\n' | nc 127.0.0.1 1567 < ~/test.txt
问题是我的回声被忽略了 :(
任何想法如何结合回波和文件作为命令的输入? ( nc
只是一个例子)
注意:将回声和文件都写入另一个文件不是首选的解决方案,因为我正在尝试测试流的真实场景。 复制上载文件没有抓住重点。
只有一个标准输入,您不能同时管道传输和重定向。
创建完整的输入,然后通过管道发送该输入:
(echo -e 'upload\n<uploadid>\n'; cat ~/test.txt) | nc 127.0.0.1 1567
从理论上讲,最有效的方法是使用here文档:
nc 127.0.0.1 1567 <<EOF
upload
<uploadid>
$(<test.txt)
EOF
这避免了使用管道或调用cat
引起的任何额外的进程创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.