Question

The scala interpreter allows shebangs, but strangely, scalac borks on them. Are there any tricks like these to get around this flaw?

Was it helpful?

Solution

#! in scala must be closed with !#. For example:

#!/bin/bash
script_dir=$(cd $(dirname "$0") >/dev/null; pwd -P)
classes_dir=${script_dir}/build/classes
src_dir=${script_dir}/src

mkdir -p ${classes_dir}
scalac -d ${classes_dir} $(find ${src_dir} -name '*.scala')

exec /usr/bin/scala -classpath ${classes_dir} "$0" "$@"
!#

OTHER TIPS

Why not strip them transparently before invoking scalac in your build script?

I don't think this is a question of "obscure shebang syntax", but rather a "language specification" issue.
The Wikipedia article on Shebang does mention:

The contents of the shebang line will be automatically ignored by the interpreter, because the # character is a comment marker in many scripting languages.
Some language interpreters that do not use the hash mark to begin comments, such as Scheme, still may ignore the shebang line.

So if scalac hasn't in its specification the directives to ignore the first lines as "script header" like Scheme, we need to wait on your Jira case 5179.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top