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?


  • 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
    Commented Feb 10, 2014 at 14:15
  • The # is part of the value, it appears on the right side of the equals sign.
    – user2234422
    Commented Feb 10, 2014 at 14:17

1 Answer 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

You must log in to answer this question.