Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Simple scenario: I'm looking for a wsdl file lost in the middle of a project.

$ find -name '*.wsdl'

Now that I know where it is, I want to do something with this file, say edit it. Instead of copy/pasting the path behind my command, is it possible to use the path returned by find earlier ? Just like it's possible to access the last argument you've typed with !$ or you last command with !!.
I've read that it was possible with $?, but it only returns me an error: 0: command not found

$ echo $?
0: command not found
share|improve this question
possible duplicated Output of last shell command – Braiam Jul 25 '13 at 13:54
Sounds like, ok thanks. – Anto Jul 25 '13 at 13:56
up vote 13 down vote accepted

Run the command in the command substitution:

output=$( find -name '*.wsdl' )
echo "$output"

The output is now stored in the output variable which you can use as many times as you like.

share|improve this answer

There is no special bash variable for that.

$? contains the exit code of the last command (0 = success, >0 = error-code)

You can use the output of find with the -exec flag, like this:

 find -name  '*.wsdl' -exec emacs {} \;

The {} is replaced with the file name found by find. This would execute the command for every found file. If you want to execute a command with all found files as arguments use a + at teh end like this:

  find -name '*.wsdl' -exec emacs {} +

This would open one emacs instance with all found .wsdl files opened in it.

A more general solution is to store the output in a variable:

result=$(find -name '*.wsdl')
emacs $result

This works with all commands, not just find. Though you might also use xargs:

  find -name '*.wsdl' | xargs emacs {}
share|improve this answer

Here's a quick hack that should do what you want with minimal keystrokes, if you don't mind that the last command is executed twice.

Use backtick, ala:



$ find . -name HardToFind.txt
$ vim `!!`

*edit: I see the above linked "possibly duped" question also contains this answer. still relevant directly to this one, so leaving it, but sorry for the dupe.

share|improve this answer
Very clever. I think this should be the accepted answer as it solves the most common case of not knowing you need the output until you've already run the command. – Paul Ruane Apr 19 at 16:38
I agree, this is what I came here looking for. Doing anything on the previous line defeats my purpose, to retroactively decide I want to do something with the last returned value. (Checkout a branch I found via git br | grep in my case) – Jack Casey Jul 21 at 0:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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