File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java args from unix script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java args from unix script" Watch "Java args from unix script" New topic
Author

Java args from unix script

Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Hi, I am trying to run the following unix script (bash shell):



This essentially does the following:
java Test "hello world"

My Test program simply prints out the arguments, and the output is this:
java Test "hello world"
hello
world

However, when I manually type the command in
java Test "hello world", the output is what I would like:
hello world

I'd like my app to print out:
hello world

on unix as well. I have added quotes to the string and as you can see, the java command being executed looks well formed, but unix still insists on parsing the argument with the space. I'm not much of a unix scripter, but could anyone clue me in as to how to get my program to behave how I'd like? Thanks.

Jeff
Ed Thompson
Ranch Hand

Joined: Jan 20, 2006
Posts: 43
The issue is not with Java, but with how shell scripts resolve variables.

The following works:



Even if the voices <i>aren't</i> real, they still have some good ideas!
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Ed, thanks for that info. It works as you said.

Now I know this gets a little off topic, but is there a way to concatenate those two statements into a single command that works, such as:

EXE="${RUN} "{ARGS}""
${EXE}

This above syntax doesn't work because of the nested double quotes, but is there a way to properly resolve this? Thanks.
Ed Thompson
Ranch Hand

Joined: Jan 20, 2006
Posts: 43
I tried to make it work that way, and I am pretty sure there is a way to do it, but I couldn't find the right combination of quotes and brackets in the few minutes I spent on this.

But is is somehow an issue of the right combination of quotes and brackets in the UNIX shell script.

(Brackets may only be an issue when calling shell script methods, I can't remember)
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Yeah, I spun my wheels for a bit and can't come up with a way either. The reason I was doing it this way is so I could print out the command that was being executed (and it makes it easier to print when it's one variable and to keep the printout current if the command being executed changes).

I appreciate the help, and if you think of anything else, just drop me a line here. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java args from unix script