According to this The script command accepts a local file as an argument and will replay commands found there, one at a time.
Reading from the file behaves exactly like inside the interactive shell, so lines starting with // will be considered as comments and ignored, while lines ending with \ will trigger line continuation.it is not possible to pass multiple commands on one line in spring-shell ,however you can modify the function to receive a string then split it or receive a string array and afterwards process the string or array yourself.
@ShellMethod("Add or subtract ,two integers together.")
public static String add(String args) {
args=args.trim();
String output="";
if(args.contains(";")){
for(String arg:args.split(";"))
{
arg=arg.trim();
if(arg.split(" ").length==3)
{
int first_fig=0;
int second_fig=0;
try{
first_fig=Integer.parseInt(arg.split(" ")[1]);
second_fig=Integer.parseInt(arg.split(" ")[2]);
}catch (Exception ex){
// System.out.println("Invalid Argument");
output+="Invalid Argument\n";
continue;
}
if(arg.split(" ")[0].equalsIgnoreCase("add"))
{
output+= (first_fig+second_fig)+"\n";
continue;
}else if(arg.split(" ")[0].equalsIgnoreCase("subtract"))
{
output+= (first_fig-second_fig)+"\n";
continue;
}else{
output+="Invalid Argument\n";
continue;
}
}else{
output+="Invalid Argument\n";
continue;
}
}
}else{
if(args.split(" ").length==3) {
int first_fig = 0;
int second_fig = 0;
try {
first_fig = Integer.parseInt(args.split(" ")[1]);
second_fig = Integer.parseInt(args.split(" ")[2]);
} catch (Exception ex) {
output+="Invalid Argument\n";
}
if (args.split(" ")[0].equalsIgnoreCase("add")) {
output+= (first_fig+second_fig)+"\n";
} else if (args.split(" ")[0].equalsIgnoreCase("subtract")) {
output+= (first_fig-second_fig)+"\n";
} else {
// System.out.println("Invalid Argument");
output+="Invalid Argument\n";
}
}else{
// System.out.println("Invalid Argument");
output+="Invalid Argument\n";
}
}
return output;
}
Then you can comfortably call it like :
shell> add 1 2; add 3 4