Below is my bash script to setup a proxy, I am by no means an expert in bash. I suspect there is a better way to write this, any tips would be appreciated.Is there a better way to do nested while-loops and if-statements?#!/bin/bashset -e    #functionsfunction yesno() {  while read -n1 -r -p [y/n/QUIT] > ; do    case $REPLY in      y|n) return;;      q) echo; echo; exit 1;;      *) printf \nERROR - Invalid response, please enter Yes OR No.\n;;    esac  done}function startover() {  printf \n\n\e[1m\e[31mStarting Over...\e[0m\n  sleep 2  unset proxyport proxyhost}    shopt -s nocasematch    while true; do      printf \nIs a proxy required to access outbound \e[1m\e[7mHTTP/HTTPS\e[0m sites?\n      yesno      if [[ $REPLY == y ]]; then        printf \n\nPlease enter your proxy url\nExample - \e[1m\e[7mproxy.example.com:8080\e[0m\n        while read -r -p Proxy >  proxy; do          if [[ $proxy =~ ^https:// && $proxy =~ :[0-9]{1,5}$ ]]; then            printf \nERROR - HTTPS with a port is not supported, please re-enter without '\e[1m\e[97m\e[41mHTTPS://\e[0m' prefix\n          elif [[ $proxy =~ ^(https?://)?([a-z0-9][-a-z0-9\.]{0,61}[a-z0-9]\.[a-z]{2,5})?.((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))?(:[0-9]{1,5})?$ ]]; then            if [[ $proxy =~ :[0-9]{1,5}$ ]]; then              proxyport=${proxy##*:}              proxy=${proxy%:*}              echo Port entered $proxyport            elif [[ $proxy =~ ^https:// && ! $proxy =~ :[0-9]{1,5}$ ]]; then              proxyport=443              echo URL starts with HTTPS, assuming $proxyport            else              proxyport=80              echo No port entered, assuming $proxyport            fi            proxyhost=${proxy##*/}            break          else            printf \nERROR - \e[1m\e[97m\e[41m$proxy\e[0m is not supported please try again\n          fi        done        printf \nCreating Proxy Settings\n        sleep 2        printf Proxy Hostname: \e[1m\e[97m\e[44m$proxyhost\e[0m\nProxy Port: \e[1m\e[97m\e[44m$proxyport\e[0m\nDoes the information above look correct?\n        yesno        if [[ $REPLY == n ]]; then          startover        fi      fi      break    done    shopt -u nocasematchUpdate 4/6/17I have improved the regex so it now supports IP and hostnames, i am still working on actually setting the proxy settings.
Make my set proxy script better
beginner;bash