Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 7 down vote accepted

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
share|improve this answer
+1 - This seems to be a solid solution. But I would appreciate if the tools were built-in or available in a standard linux environment. – schmijos Nov 20 '12 at 14:52

Curl can read passwords from ~/.netrc. Add a line like this to ~/.netrc:

machine bitbucket.org login schmijos password swordfish

and run

curl --netrc --digest --user schmijos https://bitbucket.org/u/p/get/tip.zip -o tip
share|improve this answer
~/.netrc does not store encrypted passwords. Alternatives like crypt have to be used. – schmijos Nov 20 '12 at 14:34
@JosuaSchmid If you encrypt the password, you'll have to enter the decryption password. You can put .netrc on an encrypted filesystem, that's an orthogonal concern. Did you want to get a password prompt if necessary? I didn't get that impression from your question. – Gilles Nov 20 '12 at 17:08
You are right. I don't want the password to be stored (in any insecure way). – schmijos Nov 20 '12 at 19:41
@JosuaSchmid Define insecure. If you don't want the password stored at all, why aren't you typing it when Curl prompts you to? – Gilles Nov 20 '12 at 20:19
The script should be executed in background. – schmijos Nov 21 '12 at 7:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.