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 8688037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:15:42+00:00 2026-06-12T23:15:42+00:00

I am currently trying to make a bash script that will go into every

  • 0

I am currently trying to make a bash script that will go into every folder in ./ and compile blah.java, then run blah sending in a number for an input, and put the output in a file that I have named. I have something that is somewhat functional, but it only goes into the first directory, and after that it fails on me. I currently have…

#! /bin/bash


for i in $(find . -maxdepth 1 -type d)
do

    pwd
    cd $i
    pwd

    if [ -f "blah.java" ];
    then
        javac -cp . blah.java
        echo "17" | java -cp . blah - > blahresult17
        echo "43" | java -cp . blah - > blahresult43

    fi

done

I think it is having problems, because it is trying to go into a directory from ./ once it goes into a subdirectory, but obviously from the subdirectory it doesn’t exist.

  • 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-12T23:15:43+00:00Added an answer on June 12, 2026 at 11:15 pm

    You’re missing a fi on your if, but that’s presumably a cut and paste error, not the source of your failure. The likely problem is that once you do the first cd, the following cd commands are relative to where you were, not where you are now. You can work around this with pushd/popd instead, or running the cd and java bits in a subshell so that the cd does not persist to the next loop iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to make a bash testing script that will... 1) Go
I'm trying to make a bash script that will talk to a java program
I'm trying to write a shell script that will make several targets into several
I am currently attempting to make a bash script that executes a Java main
I'm currently trying to make a GreaseMonkey script that will allow a user to
I'm currently trying to make a program that conjugates verbs into Spanish. I've created
I am trying to make a bash script which will tar all folders individually
I am currently trying to write a script that will loop through multiple directories.
I'm currently trying to make an orientation calculator in java and I'm having a
I am currently trying to make an application that allows the user to create

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.