【问题标题】:setting ubuntu system variable when value starts with?当值开始时设置ubuntu系统变量?
【发布时间】:2014-07-16 08:27:12
【问题描述】:

我正在尝试在 ubuntu shell 中设置系统变量。

export VARIABLE=!password!

输出:

-bash: !password!': event not found

所以我尝试使用引号:

export VARIABLE="!password!"

输出:

-bash: !password!: event not found

甚至

export VARIABLE='!password!'

没有输出,但是当我尝试查看我得到的变量时:

VARIABLE='!password!'

这不是我们想要的。

我也尝试在这里和那里使用反斜杠,但没有成功。请帮忙,任务是使用密码创建系统变量:!密码! (以感叹号开头和结尾。)

【问题讨论】:

  • when i tried to see the variable i get: VARIABLE='!password!' which is not the desired one。抱歉,这不正是你说的你想要的吗?
  • 导出变量='!密码!'没有输出,但是当我尝试查看我得到的变量时:VARIABLE='!password!',这是预期的,但是你想用它做什么或者你的实际问题是什么
  • 这似乎是需要的,我很困惑,因为 shell 显示了这个撇号,我认为它就像不同的字符串。

标签: linux bash shell ubuntu


【解决方案1】:

如果你这样做:

VARIABLE='!bla!'

然后

echo $BLA

你得到

!bla!

这似乎是您想要的结果。

要使其可用于子shell,请不要忘记在上面添加export

【讨论】:

  • 当变量带撇号或不带类似时,脚本是否有区别:VARIABLE='system' 或 VARIABLE=system
  • @Arm 是,但如果变量是简单的单个非空格非特殊字符串,则不是。参见例如this tutorial on quotes in sh.
猜你喜欢
  • 2016-03-31
  • 1970-01-01
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
  • 2019-11-19
  • 2018-06-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多