Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

$ find -name '*.wsdl'
./some/very/very/long/way/to/some/lost/directory/filename.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
2  
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
add comment

2 Answers 2

up vote 4 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
add comment

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
add comment

Your Answer

 
discard

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.