Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I often run commands using subshells, and sometimes would like to have the subshells expanded before I run something.. This way I could verify what I'm doing, and possibly edit what's about to happen as well.

For example, how can I get the following command line to be expanded before I run it, so I can edit the results of the subshell?


$ find -name "test.txt" 

$ mv $(!!) /tmp/new.txt

I'd like to see the subshell expanded before I run the command, like so:

$ mv /tmp/test.txt /tmp/new.txt

Is there some way to do this?

share|improve this question
zsh can do this, but I'm fairly certain bash cannot. In zsh if you have your cursor on the parameter, and hit TAB, it'll expand it – Patrick Apr 25 '13 at 13:58
I've since switched to zsh and it's great and does this, as you suggest... nice tip! I'll leave the original answer here, as it was a bash question. – Brad Parks Dec 10 '14 at 20:17
up vote 4 down vote accepted

shell-expand-line (\e\C-e) expands command substitutions in bash.

$ bind -p|grep shell-ex
"\e\C-e": shell-expand-line

$(!!)\e\C-e would run the previous command again and insert the output:

"\eo": "$(!!)\e\C-e"

It also expands other command substitutions, but there is no command like shell-expand-word.

In bash 4.0 or later you could also enable globstar, type **/file.txt, and use glob-complete-word (\eg) or glob-expand-word (\C-x*).

share|improve this answer

Here’s a handy trick — add this line to ~/.inputrc (creating the file if necessary):

Control-x: shell-expand-line

Note you could also either of the following to expand only history, or your aliases, or both:

Control-x: history-expand-line


Control-x: alias-expand-line


Control-x: history-and-alias-expand-line

This was gleaned from this blog, and this question on SuperUser, which is very similar:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.