Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the source of the current .bashrc file?

So I've just echo into bashrc, and removed everything there. But my shell wasn't closed or reloaded, so the source of my bash is old. Is there a way to see the source of my current bashrc file?


2 Answers

You can get a fairly complete dump of the current bash shell's environment with the bash commands set (with no arguments, it dumps the current environment variables and functions) and alias (similarly, dumps aliases). These may help you reconstruct a lot of the old .bashrc files.

However, you should keep in mind that these don't show the old .bashrc itself, they show its results. For example, if the default system PATH was /usr/bin:/bin:/usr/sbin:/sbin and your old .bashrc contained

PATH="$PATH:/opt/X11/bin"

this'll just show the net result:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

If you copy that into your new .bashrc, and the system PATH ever gets updated (e.g. to include /usr/local/bin), your .bashrc will erase the update.

So, you shouldn't just take the output of set and alias and use that as your new .bashrc. But you can use them as reminders of what used to be there, and also use them to avoid e.g. having to rewrite any complex functions and such you had defined.

like image 101
Gordon Davisson Avatar answered Jan 24 '26 09:01

Gordon Davisson


No, basically. Bash evaluates the contents of your login scripts, but doesn't keep them around. You may be able to reconstruct parts of them by looking at your current environment (with the env command), but most of it is gone. Bash doesn't offer advanced reflection.

Consider this a learning experience and let it motivate you to make back-ups and keep important configuration in version control from now on.

like image 41
Cairnarvon Avatar answered Jan 24 '26 09:01

Cairnarvon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!