mcandre
mcandre

Reputation: 24612

Shebangs in scalac code

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

Upvotes: 1

Views: 391

Answers (3)

Noel Yap
Noel Yap

Reputation: 19788

#! 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" "$@"
!#

Upvotes: 2

VonC
VonC

Reputation: 1325137

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.

Upvotes: 0

user268396
user268396

Reputation: 11986

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

Upvotes: 0

Related Questions