简体   繁体   中英

Why is Groovy script trying to run as shell script?

The following script:

#!/opt/groovy-1.8.6/bin/groovy

final env = []

outputs:

$ ./small.groovy 
./small.groovy: line 3: final: command not found

What needs to be done to get it to run as Groovy (without having to call Groovy explicitly)?

I'm not sure why you are seeing that error, but the usual way to run Groovy scripts directly — in a Unix-like environment — is to use:

#!/usr/bin/env groovy

println "Hello World"

This ensures that all environment variables are loaded correctly, such as JAVA_HOME .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM