0

I am trying to set some environment variables permanently by editing the /etc/environment file. One of my environment variables has a "#" in it and some text after the "#". Everything after the "#" gets commented out.

How do you set a variable with a "#" so the "#" is part of the variable and doesn't comment out the rest of the variable after the "#"? Is there a better way I should be setting environment variables so that I do not need to set them every time I log in?

Thanks!

migrated from stackoverflow.com Feb 24 '14 at 19:15

This question came from our site for professional and enthusiast programmers.

  • is # part of the name or part of the value? That is, does it appear on the left or right side of the equals sign? – Rob Feb 10 '14 at 14:15
  • The # is part of the value, it appears on the right side of the equals sign. – user2234422 Feb 10 '14 at 14:17
1

There is no way in /etc/environment to escape the #(as it treated as a comment) as it is being parsed by he PAM module "pam_env" and it treats it as a simple list of KEY=VAL pairs and sets up the environment accordingly. It is not bash/shell, the parser has no language for doing variable expansion or characters escaping.

Anyway, to get around this limitation, you might move your global environment variables into a file in /etc/profile.d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy