tags:

views:

57

answers:

2

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

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. I tried & and &- but had no luck. I am not sure what &- does.

+2  A: 

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.

Matthew Flaschen
+3  A: 
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).

wRAR