The Beanshell documentation implies that you can run a script using this format on the command line:
java bsh.Interpreter script.bsh [args]
The only problem with this is that I cannot get it to work. I know how to call other scripts with args from a Beanshell script but I cannot get the initial script to take args. Help?
For example, a beanshell script like this one, wont parse the args:
import java.util.*;
for (int i=0; i < args.length; i++) {
System.out.println("Arg: " + args[i]);
}
Also, this doesn't work either:
import bsh.Interpreter;
for( i : bsh.args )
System.out.println( i );
The command-line arguments are available under bsh.args
, not args
. So if you change all instances of args
in your code with bsh.args
, you should be good to go. Reference: Special Variables and Values.
This worked for me:
for (arg : bsh.args)
print(arg);
Example:
$ bsh foo.bsh 1 2 3
1
2
3