Shell script to set environment variables permanently

半世苍凉 提交于 2020-07-19 06:01:12

问题


I need to write a shell script to set environment variable and modify path variable permanently. Is there in any way to modify bashrc file through script?


回答1:


Yes, you write a script that appends to .bashrc with the >> redirection operator:

echo Your Text >> ~/.bashrc

See also I/O Redirection




回答2:


Is there in any way to modify bashrc file through script?, you don't need to do that.

Just manually set the required variable in .bashrc once that will do.




回答3:


I would prefer modifying the .bashrc file directly




回答4:


Your question is too general. You should specify what kind of changes you need to make. What some answerers don't seem to imagine is that you might need to script this in order to make changes to multiple accounts on a system, for example.

In general, you can use any technique that you would use on any other text file. One way would be to use sed.



来源:https://stackoverflow.com/questions/11427106/shell-script-to-set-environment-variables-permanently

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