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=installerrormsg=\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 ] && { ! ([ -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} > ~/bin/apt-proxy         chmod 777 ~/bin/apt-proxy         PATH=~/bin:$PATH         addpath=export $PATH         sudo cat ~/.bashrc $addpath > ~/.bashrc   else         printf $errormsgfiMy question is: is this code acceptable, or should I improve it? If the answer is not, then please give me some hints.
apt alternative for proxy environment with bash shell
beginner;bash;linux;shell
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 thereecho '[[ :$PATH: == *:$HOME/bin:* ]] || PATH=$HOME/bin:$PATH' >> .bashrc# create the apt-proxy scriptcat <<'END_SCRIPT' > ~/bin/apt-proxy#!/bin/bashstty -echoprintf Password for %s:  $LOGNAMEread passwordstty echoechoexport http_proxy=http://${LOGNAME}:${password}@10.20.10.50:3128sudo -S apt-get $@ <<< $passwordEND_SCRIPTchmod 755 ~/bin/apt-proxycat <<INSTRUCTIONSThe 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 ...INSTRUCTIONSmkdir -p dir will silently do nothing if the directory already existsyou only need to add the user's bin dir to the PATH if it is not already thereDO 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 fileuse sudo -S and pass the user's password via stdin