Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:03:55+00:00 2026-06-02T20:03:55+00:00

On bash, I have the following (typical) scenario: ~/some/dir$ find | grep java which

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:03:56+00:00Added an answer on June 2, 2026 at 8:03 pm

    With BASH history you can come close to [whatever the previous command returned on line 5]

    Here is an example

     $ find -name "*.java"
     src/file1.java
     ...
     src/file5.java
     ...
     $ vi $( !! | head -5 | tail -1 )
    

    In this example !! represents [whatever the previous command returned] in the sence that the command is executed again.

    The following command
    | head -5 | tail -1 is a rather awkward way to say [take line 5] from the input

    If you are after a particular filename you could as well specify that in the search expression as

    $ vi $( !find | grep file5 )
    

    If find takes a long time to execute you could save the output of find into a file and use that file instead.

    $ find -name "*.java" | tee filelist.save
     src/file1.java
     ...
     src/file5.java
     ...
     $ vi $( grep file5 filelist.save )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bash script: #DIR is something like: /home/foo/foobar/test/ without any whitespace
I have the following code which should put programs startable in Bash. if [
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I have found following working example of CGI with bash. If I change first
I have the following bash code, which is copied and pasted from bash cookbook
I have the following code: #!/bin/bash for f in `find . ! -type d`;
I have the following bash script which I will use to analyze all report
I have the following code which I call google #!/bin/bash q=$1 open http://www.google.com/search?q=$q It
I'm a newbie in bash scripts and have the following problem : I'm trying
I have a following bash script: 1 #!/bin/bash 2 query='query= SELECT * WHERE {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.