Redirect STDIN in bash?

前端 未结 2 1607
时光取名叫无心
时光取名叫无心 2021-01-19 01:43

For an example i would like to login to mysql with a password. i KNOW i can use -pmypass but i want to learn how do i redirect stdin in bash. So my test is

m         


        
相关标签:
2条回答
  • 2021-01-19 02:15
    command <<< "input"
    

    That's a bashism and echo solution is more common in scripts, though my solution can be more handy in an interactive shell (and I doubt any of these solutions works with mysql, but your question is more general).

    0 讨论(0)
  • 2021-01-19 02:26

    Normally, it's just:

    echo password|command
    

    But many programs, including MySQL, that read passwords don't actually read from stdin. Rather, they interact with the terminal directly. See Trick an application into thinking its stdin is interactive, not a pipe.

    0 讨论(0)
提交回复
热议问题