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?
e.g.
$ find -name "test.txt"
/tmp/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?
Best Answer
shell-expand-line
(\e\C-e
) expands command substitutions in bash.$(!!)\e\C-e
would run the previous command again and insert the output: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 useglob-complete-word
(\eg
) orglob-expand-word
(\C-x*
).