I have nested aliases and I want to resolve all of them before executing the command. How do I do that?
If there is a function that is not bound to any keys then M-x foobar
is fine for me too. I could even use external command (type
, command
, which
, whatever). I tried everything from the thread Why not use "which"? What to use then? but nothing works.
Best Answer
Note that Ctrl-Alt-E in
bash
does not only expand aliases. It also expands variables, command substitution (!), process substitution (!), arithmetic expand and removes quotes (it doesn't do filename generation (globbing) or tilde expansion).It doesn't always manage to expand aliases. So while it has its uses, it's important to realise its outcome potentially changes the meaning of the command line, has side effects and is potentially dangerous.
For instance in:
If I press
M-C-E
here, that gives me:Which gives me a completely different command line altogether (and imagine what would have happened if I had had
rm -rf *
instead ofpwd
above) and doesn't expand thefoo
alias.With
zsh
, to build up on Gilles' note on aliases expanded inside functions, you could do:That will expand the aliases only if the current command line is syntactically valid (so it doubles as a syntax checker).
Contrary to
bash
's M-C-E, it also resolves the aliases fully. For instance if you have:Will be expanded to:
Note that it also canonicalises the syntax so things like:
will be changed to: