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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:01:13+00:00 2026-06-11T06:01:13+00:00

I wrote a script that would generate the appropriate arguments to javac to compile

  • 0

I wrote a script that would generate the appropriate arguments to javac to compile my project in an effort to grow more proficient at shell scripting.

The weird this is.. The script works perfectly, but if the script runs javac with those parameters it doesn’t work, and if I run the exact same command in the interactive shell it does. Everything is outputted with absolute paths, so I’m pretty much at a loss here.

Example directory structure:

src/File.java
src/File.png
src/dir/File2.java
jars/Library.jar

Expected output:

build/File.class
build/File.png
build/dir/File2.class

The shell script:

#! /bin/sh

cwd=$(pwd)

if [ -d "build" ]; then
    rm -rf $cwd/build/*
else
    mkdir $cwd/build
fi

find $cwd/src \( ! -path '*/.*' \) -type f ! -iname "*.java" | xargs -I{} cp --parents {} $cwd/build

cmd=$(echo javac -sourcepath $cwd/src -classpath $(find $cwd/jars -type f | awk '{ printf("\"%s\";", $0);}'  | awk '{ print substr($0, 0, length($0)); }') -d $cwd/build $(find $cwd/src \( ! -path '*/.*' \) -type f -iname "*.java"))

$cmd
echo $cmd

Command output:

javac -sourcepath /home/test/src -classpath "/home/test/jars/Library.jar" -d /home/test/build /home/test/src/File.java /home/test/src/dir/File2.java

My actual project is too large to post here, but basically what happens is I get a huge amount of error output, as if the classpath was improperly set (they’re errors on library functions). If I copy the command from the echo statement, paste it, and hit enter it works perfectly.

I don’t get it.

Any ideas?

  • 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-11T06:01:14+00:00Added an answer on June 11, 2026 at 6:01 am

    The quotation marks you put around the argument to -classpath are treated literally, because they are part of the value of $cmd. They are not removed after $cmd is expanded and the resulting string is parsed as a command line. It’s as if you had typed at the command line

    $ javac -sourcepath /home/test/src -classpath \"/home/test/jars/Library.jar\" -d /home/test/build /home/test/src/File.java /home/test/src/dir/File2.java
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a script that uses xcodebuild to generate an AdHoc build of an
I would like to write a program or script that would generate .vcproj and
I am required to write a script that would download a file (based on
Not sure this is possible, but looking to write a script that would return
Would it be possible to write a script that gave the user the ability
How would one write a sql server DDL script that can: For each table
I have wrote a script that was run from a spreadsheet. I had One
I am trying to wrote a script that, when the page is loaded, change
My minecraft server tends to crash fairly often so I wrote a script that
I wrote a PHP script that retrieves values from a MySQL Query. I used

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.