我正在尝试设置系统范围的环境变量。
我正在编辑 /etc/environment
文件。我在文件中添加 var="name#12"
。我注销并再次登录以显示更改。
但是 echo $var
给了我 name
。
我试过用 \
转义 #
,比如 var="name\#12"
,但没有用。
我还尝试使用 ''
而不是 ""
。
谁能帮我解决这个问题?
最佳答案
男人狂欢:
COMMENTS
In a non-interactive shell, or an interactive shell in which the interactive_comments option to the shopt
builtin is enabled (see SHELL BUILTIN COMMANDS below), a word beginning with # causes that word and all
remaining characters on that line to be ignored. An interactive shell without the interactive_comments
option enabled does not allow comments. The interactive_comments option is on by default in interactive
shells.
在/etc/profile.d/中创建文件 myvars.sh 并将其添加到文件中
var="name#12"
export var=$var
重新登录后
$ echo $var
name#12
to disable comments in interactive shell:
$ shopt -u interactive_comments
关于linux - 在/etc/environment文件中设置环境变量,值为 "#"字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54597126/