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
答案 0 :(得分:1)
在bash
中,您只需编写
run() {
javac "$1".java
java "$1" "${@:2}"
}
对于POSIX兼容性,您只需稍微长一些时间:
run() {
fname=$1
shift
javac "$fname".java
java "$fname" "$@"
}