This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute shell with space-contained arg in Linux

 
Zee Ho
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers, When I execute the java program (described in a shell)in linux machine with white-space contained argument, the prgram received more arguments than expect, but I have already enclose the argument using double quote.

I use the command like this

deploy.sh "argu ment 1".

but the program prompt it receive 3 argument than 1.

in deploy.sh


#!/bin/sh

. ./set_classpath.sh

date >> ../../logs/cif_deployment.out
date >> ../../logs/cif_deployment.err

java -Xbootclasspath/p:lib/xalan-2.6.0.jar:lib/xercesImpl-2.6.2.jar:lib/xml-apis-1.2.01.jar -Dorg.xml.sax.parser=org.xml.sax.helpers.XMLReaderAdapter -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser -Dlog4j.configuration=log4j_deployment.properties -classpath $CIF_CLASSPATH com.core.cif.deploy.DeployTool $1 $2 $3 >> ../../logs/cif_deployment.out 2>> ../../logs/cif_deployment.err


is there any mistake I make?
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is caused by the shell script stripped off your double quote.
To make it work you have to put the double quote inside your script when calling the java class.



The weakness of above script is it will wrapped all your arguments into one,
or you can code it like before


If you are VERY SURE there will always be 3 arguments, because is you do not pass enough arguments..the double quotes in the above script will pass empty string to your java program as argument...so your java program will always have 3 arguments.

I hope that make sense.
 
Zee Ho
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great, thx very much.

It is really a hard time for me to work on linux.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic