When I did which groovy
, I got the below output:
/usr/local/bin/groovy
So I went ahead and created a helloworld.groovy
with the below content
#!/usr/local/bin/groovy
println "hello world"
After that I did chmod +x helloworld.groovy
and attempted to run the file with ./hellworld.groovy
and sadly, I got this error ./helloworld.groovy: line 2: print: command not found
I could get rid of the error by changing to
#!/usr/bin/env groovy
println "hello world"
Why would the first method cause the error?
您需要像这样运行脚本:
groovy helloworld.groovy
#!/bin/sh
sed '1,2d' "$0"|$(which groovy) /dev/stdin; exit;
println("hello");
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.