Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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
up vote 1 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.