Using return
prevents the extra content from being executed, but it doesn't prevent the file from filling up with all that junk over time. It also creates the problem where you accidentally add something below the return
and have to figure out why your changes aren't taking effect.
What I've done before is to add a line at the end like # END_ACTUAL_CONTENT
. I created a script that would locate this marker and delete everything located after it, and set that script to run periodically.
You can also use functions like this to neutralize those annoying installers:
function bashrc_save() { cp -f ~/.bashrc ~/.bashrc.backup }
function bashrc_restore() { mv -f ~/.bashrc.backup ~/.bashrc }
Install your program with bashrc_save; ./install.sh; bashrc_restore
and any changes that it makes to your .bashrc
file will be automatically rolled back.
I currently take this a step farther. I store my .bashrc
file (as well as a bunch of other configuration files) in a separate directory ~/.configfiles
, and I create symlinks to the locations where these files normally reside. The contents of that folder are in a git repository. I do that to make it easy to synchronize between systems, but it has the added benefit of being able to use git diff
to see all the changes an installer has made and to use git restore
to revert them en masse.