Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java slick command line app?

I want to make a slick java commandline app which doesnt include all the nasty "java -jar some.jar arguments"

instead, I would have it work just like

program -option argument

like any other commandline app. I use ubuntu linux, and it would be fine if it included a bit of .sh script or anything. I know I can just create a file with java -jar program.jar and do chmod +x file, afterwards I could run i with ./file, but then how can I pass the arguments to the program ?

like image 673
Felix Avatar asked May 20 '10 10:05

Felix


1 Answers

Use

java -jar program.jar $1 $2 $3

to access 1st, 2nd and 3rd argument of the script.

Example from http://www.ibm.com/developerworks/library/l-bash2.html

#!/usr/bin/env bash

echo name of script is $0
echo first argument is $1
echo second argument is $2
echo seventeenth argument is $17
echo number of arguments is $#

Or, even better, do as @nos suggests:

java -jar program.jar "$@"
like image 145
3 revs Avatar answered Nov 08 '22 19:11

3 revs