发送字符串标准输入 [英] Send string to stdin
本文介绍了发送字符串标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法有效地做到这一点在bash:
/我/庆典/ SCRIPT<回声这个字符串将被发送到标准输入。
我知道,我可以从管道回声输出像这样的:
回声此字符串将通过管道输送到标准输入。 | /我/庆典/脚本
解决方案
您可以使用一个行定界符
猫<<< 这是从标准输入来了
以上是相同的
猫<< EOF
这是从标准输入来
EOF
,也可以从命令输出重定向,像
差异≤(LS /箱)≤(LS在/ usr / bin中)
也可以读作
而读线
做
回声= $行=
完成< SOME_FILE
或只是
回声东西|读取参数
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
解决方案
You can use one-line heredoc
cat <<< "This is coming from the stdin"
the above is the same as
cat <<EOF
This is coming from the stdin
EOF
or you can redirect output from a command, like
diff <(ls /bin) <(ls /usr/bin)
or you can read as
while read line
do
echo =$line=
done < some_file
or simply
echo something | read param
这篇关于发送字符串标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文