brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Alt-Ctrl-e expands variables, aliases and !! on the bash line before you press Enter

Bash
~/tips/tip-bash-shell-expand-line

Alt-Ctrl-e # or press Esc, then Ctrl-e

Shows on the prompt what a command becomes once bash fills in variables and aliases.

A command full of $VARIABLES, a ~ and maybe an alias is hard to read before it runs. What will it actually do? Bash can show you right there on the prompt, and the key for it is one I’d never have found by accident.

The readline command is called shell-expand-line, and it is bound to Alt-Ctrl-e by default. It does the same expansions bash would do when you run the line: aliases, history like !! and !$, the tilde, variables, arithmetic and even command substitution. Then it leaves the result on your command line, so you read it and press Enter when it looks right.

Alt-Ctrl-e   # or press Esc, then Ctrl-e

An example. You type:

cp ~/notes.txt $BACKUP_DIR/notes-$(date +%F).txt

Press Alt-Ctrl-e and the line turns into something like:

cp /root/notes.txt /mnt/user/backup/notes-2026-11-27.txt

If $BACKUP_DIR turned out to be empty, you’d see /notes-... at the root of your disk, and you could stop before that file ends up in the wrong place. It also shows what an alias hides: ll becomes ls -alF or whatever your distro set it to.

The caveat: it really runs any command substitution on the line to get the result. With $(date) that is harmless, but with something like $(curl ...) or a command that changes things, it runs right then, when you only wanted a preview. Expansion also changes the line for good, so the short version with the variables is gone unless you undo with Ctrl-_. And on a Mac, Terminal needs “Use Option as Meta key” in the profile’s keyboard settings for the Alt part; pressing Esc first and then Ctrl-e always works.

Further reading: Some miscellaneous readline commands (GNU Bash manual), bash(1) manual page

More Bash tips echo {01..10} cmd > file 2>&1 export HISTIGNORE='ls*:pwd:cd*' #rsync -av --delete /srv/media/ /mnt/backup/media/ APP_HOST=example.com All Bash tips (52) All topics

Link