17

I made an echo command to my .bash_aliases file and erased all of my aliases, except the test alias. However, I still have a session open that has the aliases loaded (into the tcl?). Can I retrieve them from this session?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
MrUser
  • 527

2 Answers2

15

Easy trick

for alias in $(compgen -a); do type $alias; done
dchirikov
  • 3,888
  • 4
    You, sir or madame, are a life saver. – MrUser Jul 23 '14 at 13:06
  • 1
    Combine this with redirection to a file ($alias > .bash_aliases, maybe with some file regexes to get it to the right place in the file) and you don't have to type it back into the original file yourself. (That is, if you haven't already typed it in.) – trysis Jul 23 '14 at 18:12
  • 1
    While this works, I don't see the benefit over just using 'alias'. The format isn't particularly useful by comparison. – moopet Jul 24 '14 at 08:01
10

You can almost definitely just do:

alias >>./bash_aliases
mikeserv
  • 58,310