Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to expand aliases inline in bash?

$bash>alias ll='ls -l '
$bash>ls -l 
share|improve this question
up vote 58 down vote accepted

You can press Ctrl-Alt-e to perform the readline function shell-expand-line which will do alias, history and word expansions. Note that on some keyboards Meta is not Alt. You might need to press Esc then Ctrl-e

The functions alias-expand-line and history-and-alias-expand-line are not bound by default, but you can bind them by adding lines similar to the following to your ~/.inputrc file.

"\e\C-l": alias-expand-line

which would make Ctrl-Alt-l (lower case "ell") perform only alias expansion.

share|improve this answer
Can we map alias expansion to <tab> without affecting other bash completions?. – asdfg Feb 19 '11 at 15:44
@asdfg: If you do, it will break other completions. It might work (untested) to create the map as shown above and then add this additional map to replace the existing one for Tab: "\C-i": "\e\C-l\e\e" which creates a macro that performs both alias-expand-line and complete. It depends on the binding from my answer above and that the default binding for Esc-Esc remains in place. You would still be able to do Esc-Esc if you wanted to do default completion. – Dennis Williamson Feb 19 '11 at 16:03
ESC and then CTRL+E works on OS X, thanks! – Chris Wagner Sep 11 '13 at 21:24
Indeed, ESC C-e works for Bash, but C-x a works for Zsh. Also tested on OS X. – Blaz Oct 5 '15 at 19:40

This actually might be a much simpler way to do what you're trying to (bashversion >= 4.2.29):

shopt -s direxpand
shopt -s expand_aliases

shopt's man page:

share|improve this answer

This does not work. But I'm guessing/hoping something like this can be done to do what you want to do. You would have to use your own completion script. This is how you make one:

     COMPREPLY=(ls -l)
     #The next line does not work. I just hope there were a way to replace that word
     COMP_WORDS[COMP_CWORD-1]="ls -l"
complete -F _ll ll

Now source the full bash_completion file( and put the above mentioned script in a file inside bash_completion.d directory that the script you get from the url references. Let me know if it doesn't work.


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .