This is a duplicate of:
how to expand aliases inline in bash?
and
Expand subshell before executing it?
Turns out, BASH uses readline to handle this. Readline has the command shell-expand-line
, which is by default assigned the keyboard shortcut Just press Esc followed by Ctrl-Xe (see man readline
)
To test, I have the following alias defined in my .bash_profile:
alias cdh='cd ${HOME}'
Starting a new shell/terminal allows me to type:
cdh
Then press: Esc Ctrl-Xe
and readline updates the command-line to:
cd /home/user_name
MacOS 13.2.1
iterm2 3.4.15
bash 5.1.8(1)-release (x86_64-apple-darwin21.2.0)
Ubuntu 20.04.5 LTS
5.0.17(1)-release (x86_64-pc-linux-gnu)