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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:33:26+00:00 2026-05-26T23:33:26+00:00

I have this bash file: #/bin/bash PROP=-Dprop=foo bar java $PROP -jar Foo.jar So, what

  • 0

I have this bash file:

#/bin/bash

PROP="-Dprop=foo bar"

java $PROP -jar Foo.jar

So, what I want to do here is pass a space-separated list as a System Property. But this somehow does not work:

Caused by: java.lang.ClassNotFoundException: bar

So, it seems that Bash breaks -Dprop=foo bar up into -Dprop=foo, bar. I tried everything from double quoting to escaping the space character but nothing seems to work.

  • 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-26T23:33:27+00:00Added an answer on May 26, 2026 at 11:33 pm

    Note that this is really a shell syntax question … applied to a Java use-case. These answers will work for any use-cases where you need to expand shell variables on a command line while passing embedded spaces from the shell variables to the command in its arguments.

    You need to add the quotation marks around the shell script $PROP expansion:

    PROP="-Dprop=foo bar"
    java "$PROP" -jar Foo.jar
    

    For multiple -D properties:

    PROP="-Dprop1=foo bar"
    PROP2="-Dprop2=bing bong"
    java "$PROP" "$PROP2" -jar Foo.jar
    

    Yes, the multiple -D properties case is cumbersome1.

    Embedding quotes in the shell variable (as some people suggested) does not work2.

    Finally, you can pass options to the Java command using the @file mechanism, and you could generate an @-file on the fly to inject shell parameters into it. But the end result is (IMO) liable to be worse than the problem that you are trying to fix.


    1 – If there is a better way to handle the multiple properties case … that actually works for sh, bash or ksh … please comment below.
    2 – Try it and see!

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

Sidebar

Related Questions

Hopefully this should be a simple one... Here is my test.sh file: #!/bin/bash patch_file=/home/my
I have a bash script file which starts with a function definition, like this:
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
I have a script that looks like this #!/bin/bash function something() { echo hello
:/usr/local/bin# file wkhtmltopdf wkhtmltopdf: Mach-O executable i386 This file will not run. I have
I have this bash file, which asks for IP, password, etc. for OpenSSH to
I have this bash script whose job is to monitor a log file for
For example, i have this simple bash script: #!/bin/sh cd $1; And this cocoa
I have this script #!/bin/bash function labels2 () { awk ' /[0-9]/{ print substr($3,length($3)-11),
I have written this shell script as wrapper to a JAR file. The script

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.