开发者

Parameter passing with bash for clojure

I make a clj script for running clojure as follows.

java -cp $CLOJURE_JAR:$CLASSPATH clojure.main $1

The problem is that $1 is the name of the script, so I can't pass the argument with this.

The alternatives can be

java -cp $CLOJURE_JAR:$CLASSPATH clojure.main $1 $2 $3 $4 $5

hoping that the number of arguments is less than four, which might work, but I gue开发者_如何学Goss there should be a better solution to this.

What would be the better way than this?


You can use $@ to pass on all CLI arguments received by your script:

#!/bin/sh
java -cp $CLOJURE_JAR:$CLASSPATH clojure.main $@

If you want to omit some initial arguments, you can use e.g. shift, which drops the current value of $1 and shifts the remaining arguments so that $1 assumes the old value of $2, $2 that of $3 etc.:

#!/bin/sh
# prints out the first CLI argument, then passes the rest on to clojure.main
echo $1
shift
java -cp $CLOJURE_JAR:$CLASSPATH clojure.main $@

For related information, see the section entitled Special Parameters in bash's manpage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜