在linux etc / environment中,如何正确地转义前导“#”字符?

我想在AWS Linux AMI 2013.03的etc/environment存储系统范围的环境variables。 在这个例子中,我试图存储短语“#hello”。 看下面的例子。 echo $control产生

hello

我期望echo $test0 (下)产生:

#hello

而是产生一个空行。 以下是我input到/etc/environment中的testing列表:

  • control="hello"
  • test0="#hello"
  • test1="h\\#ello"
  • test2="h\#ello"
  • test3="h//#ello"
  • test4="h/#ello"
  • test5=h#ello
  • test6=h\\#ello
  • test7=h\#ello
  • test8=h//#ello
  • test9=h/#ello
  • test10='h#ello'
  • test11='h\\#ello'
  • test12='h\#ello'
  • test13='h//#ello'
  • test14='h/#ello'

如果我注销,然后重新login到机器,它会正确parsing/ etc /环境。 控制条件通过echo $control 。 但是,没有一个testing用例正确回应。 在每个实例中,散列(#)之外的string不是被删除就是被忽略。 例如, echo $test5产生h 。 有没有更好的方法来正确逃避#

有趣的是,如果我执行source /etc/environment那么所有的预期工作,并确实都echo $controlecho $test产生预期的结果。 但是,在注销/login时,问题返回…

那么这是棘手的东西,你想要做的/ etc /环境不是shell语法,它看起来像一个,但它不是,这确实是令人沮丧的。 / etc / environment背后的想法非常棒。 独立于shell的方法来设置variables! 好极了! 但是实际限制使它无用。

你不能在那里传递variables。 尝试例如把MAIL = $ HOME / Maildir /放进去,看看会发生什么。 最好只是为了任何目的而停止使用它,唉。 所以你不能用它做任何事情,如果它是由一个shell处理的话,你会期望这样做。

使用/ etc / profile或/ etc / bashrc。