简体   繁体   English

为什么Groovy脚本试图作为shell脚本运行?

[英]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)? 要使其作为Groovy运行(无需显式调用Groovy),需要做些什么?

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: 我不确定为什么会看到该错误,但是直接运行Groovy脚本(在类似Unix的环境中)的通常方法是使用:

#!/usr/bin/env groovy

println "Hello World"

This ensures that all environment variables are loaded correctly, such as JAVA_HOME . 这样可以确保正确加载所有环境变量,例如JAVA_HOME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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