Reference stdout (i.e. output of previous command) quickly in bash? Reference stdout (i.e. output of previous command) quickly in bash? unix unix

Reference stdout (i.e. output of previous command) quickly in bash?


I use backticks with history reference:

$ which rails/usr/local/bin/rails$ mate `!!`

Actually, my editor (a script starting gvim) is aliased to e, so it looks even shorter:

$ e `!!`

and you can always bind to a hotkey (see bash man page for bind command and readline support).

Also, if you can use cut buffers (select with a mouse in an X application), a hotkey for something like the below might be useful:

$ e $(xclip -out)

The command will start the editor as above with whatever was in the cut buffer on command line. Given that many paths are selectable with just a double click, a selected path can be edited very quickly.


You could always run the command in backticks:

mate `which rails`

I have to say though that it feels a little, uh, risky. What if your PATH has been tampered with so that which returns a different version of rails than what you really needed? What if which returns nothing? So, take care to close down all those error cases, or avoid them in some way (say, reading the path to rails from a config file, and writing a tool that builds that config file for you).