Noel Yap
Noel Yap

Reputation: 19758

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)?

Upvotes: 0

Views: 134

Answers (1)

OverZealous
OverZealous

Reputation: 39560

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.

Upvotes: 3

Related Questions