0

In order to use Chrome in Ubuntu and have it respect some hosts in $no_proxy, I need to set those comma-separated values with

gsettings set org.gnome.system.proxy ignore-hosts <no-proxy>

where <no-proxy> is formatted like ['localhost', '127.0.0.0/8', '::1']

What is the easiest way to convert the following no_proxy-string to that format?

localhost,127.0.0.1,example.org,.example.org,company.com,.company.com

user3105453
  • 221
  • 1
  • 2
  • 6

1 Answers1

0

I solved it with the following function:

function getGnomeProxies {
  systemProxies=$1
  spacesRemoved="$(echo -e "${systemProxies}" | tr -d '[[:space:]]')"
  IFS=',' read -r -a splitArray <<< "${spacesRemoved}"

  gnomeProxies="["

  arrayLength=${#splitArray[@]}
  for (( i=0; i<${arrayLength}; i++ ));
  do
    gnomeProxies=${gnomeProxies}"'"${splitArray[$i]}

    if [ $i -lt $(( ${arrayLength}-1 )) ]
    then
          gnomeProxies=${gnomeProxies}"',"
    fi
  done
  gnomeProxies=${gnomeProxies}"']"
}
user3105453
  • 221
  • 1
  • 2
  • 6