linux - 在/etc/environment文件中设置环境变量,值为 "#"字符

标签 linux shell environment-variables

我正在尝试设置系统范围的环境变量。

我正在编辑 /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/

相关文章:

shell - 创建一个 bash 文件用于通过 tftp 传输文件

linux - 从 shell 向 CloudWatch 发送事件

maven - 使用环境变量或命令行参数覆盖 Maven 过滤器值

linux - 在 EC2 linux 实例启动时启动程序

linux - 如何从 list 文件调用/包含 IP 地址到 ansible playbook

linux - 更改 shell 脚本以查看目录的动态列表

Git 错误 "fatal: GIT_WORK_TREE (or --work-tree=<directory>) not allowed without specifying GIT_DIR (or --git-dir=<directory>)"

Windows 用户环境变量与系统环境变量

linux - Linux 中的 Spring Data GemFire 服务器 java.net.BindException

linux - 写入 TCP 套接字不断返回 EAGAIN