When i run a certain command written in aa.sh bash file through aa.sh and then command terminal ask for password to continue execution like sudo password or git remote password to authenticate.

My Question is "how to give a password automatically in .sh file which i stored in variable when it asking to enter and then i assign that variable to continue execution".

closed as unclear what you're asking by muru, dr01, Arkadiusz Drabczyk, pLumo, Prvt_Yadav Sep 5 at 11:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • If you want to avoid the prompt and put the password you can echo the password in if the program has an option to take input from stdin. For example echo "mypass" | sudo -S whoami. – A.Danischewski Sep 5 at 13:04
  • depends on the script, provide an exemple and we might be able to help you. there's too much possibilities without more informations. – Kiwy Sep 5 at 13:13

Well for sudo password you can simply execute the script with sudo prefix and it will ask for password and it will not ask for password for any sudo commands within the file.


If you want to specify password for authentication to some application like mysql, git etc. Then you have to follow the proper syntax for that specific application. Eg: to take backup of mysql database through bash file. you can use the following command

mysqldump -u root -p "YOUR_SECRET_PASS" "DB_NAME"

Similarly for git you need to find out how it takes the password non interactively. Therefore the syntax to specify password will varies application to application. Consider the following solution in case of git. This will save credentials once it for all.

git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git
  • i gave example of sudo, but the scenario is, how to automatically fill password when password require to continue executing command – Harat Sep 5 at 11:42
  • yes, you are right. I need this kind of functionality for git – Harat Sep 5 at 12:24

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