apt alternative for proxy environment with bash shell As I am new to bash scripting, and want to use apt-get in my university.  I know that many people have issues when trying to do so.  My focus is simplicity and ease of use, but still need to be somewhat robust. 

#!/bin/bash 
string="install"
errormsg="\n\tInvalid input\n You should run this script with the following structure:\n\n sudo apt-proxy-install.sh install USERNAME PASSWORD\n\n "
DIRECTORY=~/bin/
if [ "$1" = "$string" ] &amp;&amp; { ! ([ -z "$3" ] || [ -z "$3" ]) }
   then 
         if [ ! -d "$DIRECTORY" ]; then
            mkdir ~/bin/
         fi
         printf "#!/bin/bash\nhttp_proxy=""http://$2:$3@10.20.10.50:3128"" sudo apt-get \${@:2}" &gt; ~/bin/apt-proxy
         chmod 777 ~/bin/apt-proxy
         PATH=~/bin:$PATH
         addpath="export $PATH"
         sudo cat ~/.bashrc $addpath &gt; ~/.bashrc
   else
         printf "$errormsg"
fi


My question is: is this code acceptable, or should I improve it? If the answer is not, then please give me some hints.
Storing passwords in text files is never a good idea, especially if you give that file world-readable permissions.

Try this:

#!/bin/bash 

mkdir -p ~/bin/

# add ~/bin to PATH if not already there
echo '[[ :"$PATH": == *:"$HOME/bin":* ]] || PATH="$HOME/bin:$PATH"' &gt;&gt; .bashrc

# create the apt-proxy script
cat &lt;&lt;'END_SCRIPT' &gt; ~/bin/apt-proxy
#!/bin/bash

stty -echo
printf "Password for %s: " "$LOGNAME"
read password
stty echo
echo

export http_proxy="http://${LOGNAME}:${password}@10.20.10.50:3128"
sudo -S apt-get "$@" &lt;&lt;&lt; "$password"
END_SCRIPT

chmod 755 ~/bin/apt-proxy

cat &lt;&lt;INSTRUCTIONS
The apt-proxy script has been installed. 
You may need to log out and log back in before you can use it.

usage: apt-proxy package ...
INSTRUCTIONS



mkdir -p dir will silently do nothing if the directory already exists
you only need to add the user's bin dir to the PATH if it is not already there
DO NOT store the user's password. Have the user enter it each time.
you should not even need to use sudo to edit files in your home directory.
777 permissions is overly generous: the world does not have to be able to edit the file
use sudo -S and pass the user's password via stdin