Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

This question already has an answer here:

Is there any bash command or technique through which we can enter in password alongwith the command which requires the password of superuser? for e.g

sudo apt-get install kde <password>

I am actually using it to pass it in a c program which takes in bash command and prints out the output.

share|improve this question

marked as duplicate by Eric Carvalho, Rafał Cieślak, Florian Diesch, Seth, Mik Feb 24 '13 at 18:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

I sorted it out finally

echo <mypassword> | sudo -S apt-get install <package name>
share|improve this answer
In general it is not recommended to work this way. Your password will be visible in your shell history and also in the proc filesystem. Other users might read it out. – qbi Feb 24 '13 at 15:15

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