Q:

Can the .bash_profile used to initialize a shell be recovered from a running instance?

I was an idiot and accidentally overwrote my bash_profile. by using > instead of >>, I also don't have any backups of it which won't happen if this works.
As I still have an iTerm2 window open with the old bash_profile loaded and I wondered if there was a way to get a printout of it so that I can salvage it?
I have looked at recovering files and none of the options have worked and it would be great if I could get this back because it has a couple years of aliases and variables in it.

A:

To dump shell variables and functions, run:
declare -p
declare -fp

This will dump all definitions active in your session, which will include ones that were set during the execution of your .bash_profile.
To further dump all aliases, run:
alias -p

This should provide an adequate starting place to find data in your dotfiles that may have been lost.
Flagging community wiki to avoid gaining rep from answering a known off-topic question.

