export CLASSPATH=$(JARS=(./lib/*.jar); IFS=:; echo "${JARS[*]}")
If I put this line in a bash_script.sh
and do
chmod +x bash_script.sh
and then run
./bash_script.sh
it gives the error.
Syntax error: "(" unexpected (expecting ")")
How ever I am able to run this thing directly from the prompt and get the expected result. as
$ export CLASSPATH=$(JARS=(./lib/*.jar); IFS=:; echo "${JARS[*]}")
I was wondering what is the reason for this strange behaviour.
将#!/bin/bash
添加为第一行,以强制其在bash shell中运行。
Make sure you have #!/bin/bash
at the top of your shell script. Array syntax VAR=(...)
is a bash-ism. It won't work in plain sh ( #!/bin/sh
).
By the way, that looks like a line from my answer here . If so, I encourage you to use my updated solution rather than this.
There's no need to manually build the classpath list. Java supports a convenient wildcard syntax for directories containing jar files.
java -cp "$LIB/*"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.