5

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?

ledawg
  • 151

3 Answers3

5

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

Evgeny
  • 5,476
4

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; }
Petr Skocik
  • 28,816
2

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 !$
Jakuje
  • 21,357