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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:47:27+00:00 2026-06-10T09:47:27+00:00

I am currently attempting to make a bash script that executes a Java main

  • 0

I am currently attempting to make a bash script that executes a Java main class with a path to an archive file as an argument. I want to make sure that it can handle spaces in that path, which is giving me a bit of a headache.

I want to set that path as an environment variable and call it when I execute the main class, so the script looks something like this:

export ArgPath='/Foo Path/foo.zip'

$JAVA_HOME/bin/java -cp ./foo.jar foopackage.main -a $ArgPath

Unfortunately, when I execute this in Bash, the command comes out like this:

/foo_Java_Home/bin/java -cp ./foo.jar foopackage.main -a /Foo Path/foo.zip

Java arguments can’t have spaces. Java treats “/Foo” and “Path/foo.zip” as two separate arguments. Okay, that’s not a problem. Java can handle arguments with spaces. I need to find some way to get double or single quotes around it. I’ll try to escape double quotes around the path. The script now looks like this:

export ArgPath='\"/Foo Path/foo.zip\"'

$JAVA_HOME/bin/java -cp ./foo.jar foopackage.main -a $ArgPath

Bash gives me this…

/foo_Java_Home/bin/java -cp ./foo.jar foopackage.main -a '\"/Foo' 'Path/foo.zip\"'

…which still causes Java to treat them as two separate arguments (not to mention that it wouldn’t work as a single argument anyway). I’ve tried about every combination and permutation of using single quotes, double quotes, and escaping single quotes/double quotes/spaces I can think of. Is there any way to provide the desired output of

'/Foo Path/foo.zip'

or
“/Foo Path/foo.zip”

In Bash? For that matter, is it possible to get Bash to accept an arbitrary string literal without trying to add anything to it in circumstances like these? Escaping characters doesn’t seem to work, so that may be the only option if it’s possible.

Thanks in advance.

  • 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-10T09:47:28+00:00Added an answer on June 10, 2026 at 9:47 am

    Enclose the variable in double quotes in the command invocation:

    export ArgPath='/Foo Path/foo.zip'
    
    $JAVA_HOME/bin/java -cp ./foo.jar foopackage.main -a "$ArgPath"
    

    Note that this applies generally to invoking any command (not just Java). If an argument contains spaces (etc.), enclose it in quotes (single or double). When the argument is in a variable, use double quotes.

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

Sidebar

Related Questions

I'm attempting to make a php script that can load the current weather forecast
I have one very large text file(27GB) that I am attempting to make smaller
I am currently tinkering with SIMBL, attempting to make my own plugin. I am
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
Using php coding, I'm attempting to make a script which will grab content from
I'm attempting to make a function that writes a string to the last line
I'm attempting to make a simple game of Pairs for Android. Program Structure: Menu.java
I'm attempting to make a menu bar that sticks to the bottom of the
I am attempting to create a php script that can connect thru ssh to
I'm currently attempting to make a custom lightbox-like feature on my website (www.slatewerner.com). My

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.