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?
4 Answers
Yes, you write a script that appends to .bashrc with the >> redirection operator:
echo Your Text >> ~/.bashrc
See also I/O Redirection
1 Comment
.bashrc.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.
1 Comment
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.
bashrcor you can call your script that sets the variables frombashrc. If you run the script as in. script_to_set_vars, the vars will last for that session only. Why would you want to modifybashrcthrough script?.bashrcvariables through script is when creating an installation script, for which symlinks cannot be created.