No, writing executable scala shell scripts is not rocket science. I know. I noticed however that people don’t often use scala in this fashion because it didn’t occur to them.
Have a short look at the following utility I wrote the calculate the scrabble® score for every line in the given input file. The ‘magic’ is in the first lines (which I learned
here) of the file, which passes the filename and arguments to a scala command (which must be in you path to work for this).
I you put this code in a file and make it executable (ie. chmod a+x <nameOfScriptFile>) you can execute it like
./<nameOfScriptFile> fileToScore
Cool!
Volgens http://www.artima.com/forums/flat.jsp?forum=282&thread=220878 moet het ook werken met deze twee regels als shebang:
—-
#!/usr/bin/env scala
!#
—-
!# op de tweede regel is wel wat vreemd (voor Groovy is #!/usr/bin/env groovy genoeg, zelfde voor Python, etc.), maar Scala’s ScriptRunner schijnt dat om de een of andere reden nodig te hebben.
Yep,
is also valid, and probably a bit clearer. Thanks!
Just for fun I ported your code to Groovy: http://gist.github.com/618271
I’m sorry, but I think Groovy definitely wins here.
)
Just for fun I refactored to win from the groovy version:
http://gist.github.com/618308
So… I timed a scala, groovy and java version on a huge file to get the following metrics: