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

  • Home
  • SEARCH
  • 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 1002839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:53:10+00:00 2026-05-16T07:53:10+00:00

I have a java program that I am trying to generate 3 outputs for,

  • 0

I have a java program that I am trying to generate 3 outputs for, and then rename them depending on what the input file was originally called.

The problem is that only the input file is being moved. I think this might be an issue regarding relative file commands.

Here is my script. (Also, I’m open to suggestions on making this script better looking. I’m a bash newbie.)

#!/bin/bash
########################################################
#This script compiles Main, then attempts to run each  #
#test case. After running a test case, it renames the  #
#testcase and moves it to a new directory.             #
########################################################
#echo `pwd`    <---- This was used for testing. pwd is correct

#Gets contents of "tests" directory, stores them into the array
#without the file extension.
list=(`ls tests| sed 's/\.txt$//g'`)

#Compiles Main.java
cd ./src
javac Main.java
cd '../'
mv -f src/*.class bin #*/ (formatting fix)

#Runs Main for each test case, then renames and moves the test cases.
for filename in ${list[@]}
do
echo 1 > input.txt
echo tests/$filename.txt >> input.txt
cd ./bin # Why do I need to cd to make this work?
java bin/Main < input.txt
cd ../
mv -f input.txt "scriptout/'$filename'_input.txt"
mv -f "tests/output.txt" "scriptout/'$filename'_output.txt"
mv -f "tests/listing.txt" "scriptout/'$filename'_listing.txt"
mv -f "src/intermediate.txt" "scriptout/'$filename'_intermediate.txt"
done
  • 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-05-16T07:53:11+00:00Added an answer on May 16, 2026 at 7:53 am

    You have single quotes around your variable names. Since they’re inside double quotes, the variables will be expanded but the single quotes will be included in the filenames. Try this:

    mv -f input.txt "scriptout/${filename}_input.txt"
    

    The braces will protect the variable name from being combined with following characters.

    You can do this:

    list=(tests/*)
    list=("${list[@]##*/}")    # strip dirname
    list=("${list[@]%.*}")     # strip extension
    

    These will prevent errors if there are spaces in any of the filenames.

    Use indenting to make your script more readable:

    for ...
    do
        command
    done
    

    In general, you should avoid using relative directories and use a variable as a base for an absolute directory:

    basedir=/path/to/base
    do_something $basedir/test/filename
    mv $basedir/subdir1/file1 $basedir/subdir2
    

    This can also make it so you don’t have to use cd as much.

    Are you getting any error messages? Try using set -x to turn on tracing and set +x to turn it off. Place those before and after particular sections of code so you can see what’s happening in that area.

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

Sidebar

Related Questions

I have a Java program that is launched by a batch file with a
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a java program that performs 5 different tasks. When I run the
I have a java program that is running in the background(Windows). I would like
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes
I have a Java program that generates Java classes for my application. Basically it
I have a Java program that is supplied a directory name, gets a list
I have a Java program that connects to a webserver using SSL/TLS, and sends

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.