PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 31, 2022

[FIXED] How do I get EOT to work on IF ELSE statement in bash?

 October 31, 2022     bash, environment-variables, eof, heredoc, proxy     No comments   

Issue

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

Solution

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.



Answered By - chepner
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing