问题
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