将字符串发送到标准输入 [英] Send string to stdin

查看:50
本文介绍了将字符串发送到标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 bash 中有效地做到这一点:

Is there a way to effectively do this in bash:

/my/bash/script < echo 'This string will be sent to stdin.'

我知道我可以通过管道传输来自回声的输出,例如:

I'm aware that I could pipe the output from the echo such as this:

echo 'This string will be piped to stdin.' | /my/bash/script

推荐答案

可以使用一行heredoc

cat <<< "This is coming from the stdin"

以上同

cat <<EOF
This is coming from the stdin
EOF

或者你可以重定向命令的输出,比如

or you can redirect output from a command, like

diff <(ls /bin) <(ls /usr/bin)

或者你可以读为

while read line
do
   echo =$line=
done < some_file

或者干脆

echo something | read param

这篇关于将字符串发送到标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆