小编kur*_*ing的帖子

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

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

hello

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

#hello

但它会产生一个空行。以下是我输入的测试列表/etc/environment

  • 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'

如果我注销然后重新登录机器,它将正确解析 /etc/environment.conf 。控制条件传递echo $control。但是,没有一个测试用例正确响应。在每种情况下,哈希 (#) 之外的字符串要么被压缩,要么被忽略。例如,echo $test5产生h. 有没有更好的方法来正确逃脱#

有趣的是,如果我执行source /etc/environment,那么所有的作品如预期的确都echo $controlecho $test产生预期的结果。但是,在注销/登录时,问题又回来了......

linux amazon-web-services

5
推荐指数
1
解决办法
1672
查看次数

标签 统计

amazon-web-services ×1

linux ×1