1

I have to write two scripts, one to compile my code and another one to run it. I manage to compile the code with this script:

#!/bin/bash
javac SimilaridadeP.java

And I was able to run it using this script:

#!/bin/bash
java SimilaridadeP

The problem is that I need to execute my second shell script following this command:

./execute.sh input output

Where input and output are the names of the files that I am going to use in my Java code. The problem that I am facing right now is that I don't know how I can use these both names in my Java code.

So far I managed to get both names using this code:

#!/bin/bash
in=$1
out=$2
java SimilaridadeP

But since "SimilaridadeP" is the name of my java file and it can't be called like a method with parameters I am kind of lost.

2 Answers 2

3

If your java code is already reading the command-line parameters, it's just a matter of changing the bash this way:

#!/bin/bash
java SimilaridadeP "$1" "$2"
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for the reply! So what I have in my Java class is something similar to scanf in C. My main doubt is in how do I read the command line parameters.
I did not add any validation, but here is the basics: public static void main(String[] args) { String parm1 = args[0]; String parm2 = args[1]; ..... }
2

This works with arbitrary number of arguments:

#!/bin/bash
java SimilaridadeP "$@"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.