Alex Rivera | Logout

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

Asked 2012-07-11T02:34:31.880
8

Is there a way to quickly (e.g. via a keyboard shortcut, etc.) to reference the output of the previous command's output that it wrote to stdout?

For example, if I did this:

which rails

and it returned /usr/local/bin/rails and then I wanted to open that file in textmate, I could re-type the output like this:

mate /usr/local/bin/rails

but is there a way to quickly reference the output without having to re-type it?

NOTE: I am aware I can just do mate $(which rails), but I am specifically looking to reference stdout.

Edit
Report

1 Answer

-1

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).

answered 2012-07-18T21:01:36.267

Your Answer