Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This question already has an answer here:

I am on the bash shell and I want the output of a command to appear directly in the command prompt that appears after the command has executed !

Example of what I envision it, to illustrate my idea:

locate create_tables.sql|MAGIC_command
user@localhost:~# /usr/share/doc/phpmyadmin/create_tables.sql

Now, using comman dsubstitution like this

sudo $(locate create-tables.sql)

works but immediately executes the output, I'd like to be able to edit it before. Is there a way?

share|improve this question

marked as duplicate by G-Man, cuonglm, Anthon, Archemar, lcd047 Jul 7 at 5:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3  
see this recent question which is similar. –  meuh Jul 5 at 21:03
    

3 Answers 3

I generally use the clipboard for this kind of thing

$ some_command | cb
$ cb_edit
$ `cb` #or paste it with your paste button/shortcut

The magic:

 cb() {
  if [ ! -t 0 ]; then
    #if somebody's piping in reproduce input and pipe a copy to the clipboard
    tee >(xclip -selection c)
  else
    #otherwise, print the contents of the clipboard
    xclip -selection c -o 
  fi
}
cb_edit() { cb | vipe "$@" | cb; }
share|improve this answer

In Emacs-mode type sudo $(locate create-tables.sql), Esc,Control+e

See shell-expand-line in Bash Reference Manual:

Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions

share|improve this answer
1  
Or ctrl+alt+e if you have your terminal set up nicely. –  Peter Cordes Jul 6 at 0:52

Not very elegant solution is to store the output into some tmpfile, edit that file and then run:

$ locate create_tables.sql > /tmp/tmpfile
$ vi !$    # last argument of last command
$ bash !$
share|improve this answer

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