Environment variable string getting chopped off because of special character

不羁的心 提交于 2020-08-10 20:12:10

问题


In /etc/environment I have declared a variable "myvar" as:

myvar='abc$#abc'.

I need to use the varibale in a script. When I print the variable through the script, The string gets chopped off after '$' character.

echo $myvar

Result:

abc$.

Fix(But why is this working?):

When I include source /etc/environment in the script, the variable is retrieved correctly.

#!/bin/bash

echo $myvar
source /etc/environment
echo $myvar

Result:

abc$
abc$#abc

Why is this working? And how can I make it work without using source?

来源:https://stackoverflow.com/questions/63300003/environment-variable-string-getting-chopped-off-because-of-special-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!