问题
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