linux - 在 /etc/environment 文件中设置环境变量,其值包含“#”字符
问题描述
我正在尝试设置系统范围的环境变量。
我正在编辑/etc/environment
文件。我var="name#12"
在文件中添加。我注销并再次登录以显示更改。
但是echo $var
给我name
。
我试过#
用\
like转义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
在交互式 shell 中禁用注释:
$ shopt -u interactive_comments
推荐阅读
- python - 将搜索结果链接到其自己的详细信息页面
- node.js - nodejs 读取 .ini 配置文件
- tomcat - Grails 项目 BuildConfig.groovy Tomcat 插件版本?
- java - Arraylist 不在 java 中存储值
- prolog - 使用 prolog dcg 匹配矩阵中的模式
- r - 如何使用 lapply 在 R 的列表中查找最接近的值?
- python - 我的 python 代码一直在 UTC 时间返回它的结果
- angular - 带有 POM 的 Angular Cli - Maven
- microsoft-graph-api - 有没有办法只为用户订阅?
- javascript - 无法在有状态组件根元素上使用 v-for,因为它呈现多个元素