Pipe Password to Application When Asked in Bash

bashcurlpasswordpipestdin

The following should be done in a bash script:

curl --digest --user schmijos https://bitbucket.org/u/p/get/tip.zip -o tip.zip

How can I automatically submit a password to curl when it asks for it? Since I don't want to see the password in any logfile, I won't do the following:

curl --digest --user schmijos:$password https://bitbucket.org/u/p/get/tip.zip -o tip.zip

Best Answer

Use empty:

With the password safely stored (it's a way of saying...)

$ echo password > pwd-file

Start process with empty. (You would omit -L log in the real case.)

$ empty -f -i fifo1 -o fifo2 -L log curl -u user http://example.com

Send the contents of pwd-file to empty's input pipe, which the process sees as both its stdin and /dev/tty.

$ empty -s -c -o fifo1 < pwd-file

This is what happened in the pseudo terminal:

$ cat log
<<<Enter host password for user 'user':>>>password
<<<
Related Question