Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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!

share|improve this question

migrated from stackoverflow.com Feb 24 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 at 14:15
    
The # is part of the value, it appears on the right side of the equals sign. –  user2234422 Feb 10 at 14:17
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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