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?

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