1

How would I write the following bash script replacing the actual code of the scala section (after the !#) line to be called from a .scala file and then call its main method?

#!/bin/sh
exec scala "$0" "$@"
!#
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world! " + args.toList)
  }
}
HelloWorld.main(args)

keep in mind i do not have access to scalac

2
  • Maybe this is what you're actually trying to do: stackoverflow.com/questions/15077341/… Commented Jul 10, 2015 at 20:10
  • @Kenster not quite! but this is helpful for the future Commented Jul 10, 2015 at 20:20

1 Answer 1

1

I presume you mean dividing the file into two parts...

file.scala

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world! " + args.toList)
  }
}
HelloWorld.main(args)

launch.sh

#!/bin/sh
exec scala "file.scala" "$@"
Sign up to request clarification or add additional context in comments.

2 Comments

YES! this is exactly what I was looking for! out of curiosity what does the "$@" stand for?
@Zee: Source $@ is bash internal/special variable which is expanded to all the parameters received (in this particular case by launch.sh). That means if you call ./launch.sh arg1 arg2, then "$@" will be expanded to arg1 arg2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.