Adding bash function to compile and run java with multiple command line inputs

时间:2016-08-31 18:19:37

标签: java bash

I'm trying to create a bash function to compile and run java code but that is also not restricted to a single command line argument. Thus far I have:

run() {
    javac $1.java
    java $1 $2
} 

The problem is that this only allows for one command line argument

1 个答案:

答案 0 :(得分:1)

bash中,您只需编写

即可
run() {
    javac "$1".java
    java "$1" "${@:2}"
} 

对于POSIX兼容性,您只需稍微长一些时间:

run() {
    fname=$1
    shift
    javac "$fname".java
    java "$fname" "$@"
}