Hash ("#") symbol in /etc/environment causes string to be split

Viewed 1078

I'm trying to add an environment variable to my system via

sudo nano /etc/environment

The value is a long string containing a hash, #.

With the # included, the string is not stored fully; characters after the # are gone.

Without the # included, the string is stored fully.

I have tried to wrap the string in " ":

MY_VARIABLE="34534554345 # DFGDGDFG"

I expect the variable to be stored fully, like this:

34534554345#DFGDGDFG

Not this:

34534554345
1 Answers

PAM interprets /etc/environment, not a shell. It's intended to be simple KEY=VALUE on each line with no need for quotes. # marks a comment and there is no way to escape it.

You can use /etc/profile to define your environment variable. It should make it available system wide in most cases.

/etc/environment

TEST2="12345#6789"

/etc/profile

export TEST="12345 #6789"

Result:

root@tempmon:~ $ env|grep TEST
TEST=12345# 6789
TEST2=12345
Related