I am adding an env variable to /etc/environment but because the variable value contains # sign, string is striped.MYSQL_PWD=something#noNow if I do env above code yields MYSQL_PWD=something. How can I escape hash? I've already tried \ character.
Escape hash mark (#) in /etc/environment
environment variables;login;pam
This doesn't appear to be possible with /etc/environment. It's meant as a common location for variables that's shell independent. Given this it doesn't look like it supports strings with hash marks (#) in them and there doesn't appear to be a way to escape them.I found this SF Q&A titled: How does one properly escape a leading # character in linux etc/environment?. None of these methods worked:control=hellotest0=#hellotest1=h\#ellotest2=h#ellotest3=h//#ellotest4=h/#ellotest5=h#ellotest6=h\#ellotest7=h#ellotest8=h//#ellotest9=h/#ellotest10='h#ello'test11='h\#ello'test12='h#ello'test13='h//#ello'test14='h/#ello'The accepted answer to that question and what would also be my advice:Well it is tricky stuff you want to do /etc/environment is not shell syntax, it looks like one , but it is not, which does frustrates people. The idea behind /etc/environment was wonderful. A shell-independent way to set up variables! Yay! But the practical limitations make it useless.You can't pass variables in there. Try for example put MAIL=$HOME/Maildir/ into it and see what happens. Best just to stop trying to use it for any purpose whatsoever, alas. So you can't do things with it that you would expect to be able to do if it were processed by a shell.Use /etc/profile or /etc/bashrc.Yet still another Q&A gave this rational as to why this is the case:There is no way in /etc/environment to escape the #(as it treated as a comment) as it is being parsed by he PAM module pam_env and it treats it as a simple list of KEY=VAL pairs and sets up the environment accordingly. It is not bash/shell, the parser has no language for doing variable expansion or characters escaping.ReferencesEnvironment variable in /etc/environment with pound (hash) sign in the value