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

纵然是瞬间 提交于 2020-08-20 06:35:29

问题


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:


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


来源:https://stackoverflow.com/questions/56688407/hash-symbol-in-etc-environment-causes-string-to-be-split

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!