Is not very secure, just to say that before I give the answer, since somebody could just open the file and see the password but here is how:
Suppose we want to execute the command sudo shutdown -h 1
but we do not want to type in the password. We would do it like this:
echo PASSWORD | sudo -S shutdown -h1
For example, if my password were x then it would look something like this:
echo x | sudo -S shutdown -h1
Another example is, if I wanted to do an apt-get update then upgrade without entering any password. I would do this:
echo x | sudo -S apt-get update && sudo apt-get upgrade
The first sudo (The one with the -S parameter) will grab the password from the standard input, in this case, the keyboard in the terminal. It will then hold the password for the remaining terminal session. Since in this session I am executing 2 apt-get commands, one with update and the other with upgrade, there is no need to type the password again for the second apt-get since the password is active for the session in use. So the rest of the sudo commands will not need to be provided another password until the session closes (Until you close the terminal or script using the password ends).