Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Groovy script from the command line

Tags:

unix

groovy

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?

like image 412
jjennifer Avatar asked Sep 10 '13 23:09

jjennifer


People also ask

How do I test Groovy script?

Test a Groovy application You can test Groovy applications using JUnit 4 and JUnit 5 testing frameworks. Open a class in the editor, for which you want to create a test and place the cursor within the line containing the class declaration. Press Ctrl+Shift+T and select Create New Test.


1 Answers

You need to run the script like this:

groovy helloworld.groovy 
like image 177
grantmcconnaughey Avatar answered Sep 21 '22 11:09

grantmcconnaughey