java - wrong arguments are passed to .ksh -


the arguments not being passed expected when try execute following .ksh file.

processlauncher.ksh:

/usr/java/jdk1.7.0_25/bin/java -xmx256m $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 

this code execute invoke above .ksh file:

callingclass:

public static void main(string[] args) {     string[] cmdline = {};     cmdline = new string[]{"ksh", "../scripts/processlauncher.ksh", com.mypackage.calledclass.class.getname(), "simpledf", "1099"}; } 

and code executed after calling .ksh file:

calledclass:

public static void main(string[] args) {     system.out.println("arguments passed: " + arrays.tostring(args));             if (args.length != 2) {             system.out.println("invalid arguments");             system.exit(0);     } } 

expected result after executing callingclass#main() method:

arguments passed: simpledf 1099

actual result after executing callingclass#main() method:

arguments passed: simpledf 1099 com.mypackage.calledclass

invalid arguments

the qualified classname being passed incorrectly last argument. using jdk7u25 (32-bit) on suse linux enterprise server (32-bit). however, when remove last 2 arguments java command in .ksh file (i.e $9 , $10) works fine , expected result.

can please explain going on here?

give try ${10} rather $10. ksh man page states under parameter expansion:

a positional parameter of more 1 digit must enclosed in braces.

however, better way may use entire array:

/usr/java/jdk1.7.0_25/bin/java -xmx256m "$@" 

you can see what's going wrong in following transcript:

pax> cat tst.ksh  #!/usr/bin/ksh echo " 1  = [$1]" echo " 2  = [$2]" echo " :" echo " 9  = [$9]" echo "10a = [$10]" echo "11a = [$11]" echo "10b = [${10}]" echo "11b = [${11}]"  pax> tst.ksh b c d e f g h j k  1  = [a]  2  = [b]  :  9  = [i] 10a = [a0] 11a = [a1] 10b = [j] 11b = [k] 

the multi-digit positional parameters without braces being treated single-digit ones trailing digit constant. in other words, $10 being treated ${1}0. when surround 10 braces, correct result obtained.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -