Bash Alias Expansion

Oct 12, 2025

Recently, I decided to leave the fish shell for a shell that was more suitable for scripting (POSIX-compliant). I used Fish for a long time, attracted by its interactive features, but I eventually got frustrated with its peculiarities when it comes to scripting and system administration.

So I decided to give Bash a shot (this time for real).

Fish: abbreviations

One of the features that I liked the most about Fish was abbreviations. An abbreviation is a string that is expanded into another one as you type your command line. Here are some examples:

abbr -ag o open
abbr -ag d docker
abbr -ag dc docker compose

The nice thing about this is that your history will be much more explicit and other people watching you typing will understand more of what you are doing.

Bash: alias expansion

When migrating to Bash, I was determined to abandon abbreviations and learn to live using aliases only. I randomly discovered while taking a look at bindable readline functions, that there is one called alias-expand-line… Yes, it does what it says.

bind -p | grep alias-expand-line

I decided to bind it to CTRL-SPACE.

bind -x '"\C- ": alias-expand-line'

I like the possibility of expanding aliases much more than abbreviations: it just makes much more sense to me that there is an alias, and you can decide to expand it to show or edit its body.

Here is an example:

llt | l

# first line expansion (llt + l)
ll --tree --level=2 | less

# second line expansion (ll)
eza -l -g --icons --color=always --tree --level=2 | less

Alias expansions also opens the door for using Bash completions with aliases. This is because Bash does not perform completion properly on (unexpanded) aliases.

If, for whatever reason, you would like your alias not to be sensitive to alias expansion, you could just use a function instead of an alias.