简体   繁体   English

在bash中重定向STDIN?

[英]Redirect STDIN in bash?

For an example i would like to login to mysql with a password. 举个例子,我想用密码登录mysql。 i KNOW i can use -pmypass but i want to learn how do i redirect stdin in bash. 我知道我可以使用-pmypass,但我想学习如何在bash中重定向stdin。 So my test is 所以我的测试是

mysql -u limited_user -p <text to redirect into stdin when it prompts for my pass>

I seen < filename before but i dont want to store the data in a file. 我之前看过<filename但我不想将数据存储在文件中。 I tried & and &- but had no luck. 我试过&和 - 但没有运气。 I am not sure what &- does. 我不确定是什么& - 做什么。

command <<< "input"

这是一个基础和echo解决方案在脚本中更常见,虽然我的解决方案在交互式shell中更方便(我怀疑这些解决方案中的任何一个都适用于mysql,但你的问题更为通用)。

Normally, it's just: 通常,它只是:

echo password|command

But many programs, including MySQL, that read passwords don't actually read from stdin. 但是许多读取密码的程序,包括MySQL,实际上并没有从stdin中读取。 Rather, they interact with the terminal directly. 相反,它们直接与终端交互。 See Trick an application into thinking its stdin is interactive, not a pipe . 请参阅欺骗应用程序,认为它的标准输入是交互式的,而不是管道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM