1

I'm trying to make a script that enables proxy settings if the /etc/environment file is currently empty and disables the settings if the file has text. I've written some code but not sure why the /etc/environment file is not being edited. I have blanked out the actual proxies I am using. Any help would be greatly appreciated!

#!/bin/bash

        if [ -s /etc/environment ]
        then
            cat<<EOT >> /etc/environment
            http_proxy="blank"
            https_proxy="blank"
            ftp_proxy="blank"
            export http_proxy https_proxy ftp_proxy
            EOT
        else
            > /etc/environment
        fi
Cyrus
  • 77,979
  • 13
  • 71
  • 125
bwalsh434
  • 17
  • 3

2 Answers2

5

Use <<- instead of << if you want to indent the end token EOT or move EOT to first column.

Please take a look: http://www.shellcheck.net/

Cyrus
  • 77,979
  • 13
  • 71
  • 125
0

You can also move the here document to the if statement itself.

if [ -s /etc/environment ]; then
  cat
fi <<EOT >> /etc/environment
http_proxy="blank"
https_proxy="blank"
ftp_proxy="blank"
export http_proxy https_proxy ftp_proxy
EOT

although if the if statement itself is indented, you'll still want to know how to indent the here document as Cyrus explains.

chepner
  • 446,329
  • 63
  • 468
  • 610