On bash, I have the following (typical) scenario:
~/some/dir$ find | grep java
which outputs, for example
./subdir1/subdir2/file1.java
./subdir1/subdir3/file2.java
./subdir1/subdir4/file3.java
./subdir1/subdir2/file4.java
./subdir1/subdir6/file5.java
now I know that file5.java, which is the file I was looking for (for example), is on that subdir, so I execute:
vi subdir1/subdir6/file5.java
but in order to do this I have to either type the path (I know that using the TAB key speeds it up) or copy and paste the path to the file
the question is: is there a shortcut/variable on bash (or any other shell) that references the lines outputted by the previous command, so that I can say
vi [whatever the previous command returned on the 5th line]
, and that would be a nice time saver
thanks!
With BASH history you can come close to
[whatever the previous command returned on line 5]Here is an example
In this example
!!represents[whatever the previous command returned]in the sence that the command is executed again.The following command
| head -5 | tail -1is a rather awkward way to say[take line 5]from the inputIf you are after a particular filename you could as well specify that in the search expression as
If
findtakes a long time to execute you could save the output offindinto a file and use that file instead.