문제

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

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top