You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'scala' command line tool is very useful as a linux script executor. Unfortunately it supports only one file which, can be passed as argument. But I think that in more advance system scripting it is very common to want to refactor part of scripts into separate source unit. For example I have few scripts in bash for backing up my system, but calculating paths is common part and is in separate file mirror-config.sh.
As I said before I can not do it easily using Scala as I can not provide more than one scala source file.
My current (imperfect) solution is as follows:
scala-utils.scala -> contains some common utilities for scripting
test.sh -> main script in scala wrapped in bash
test.sh file:
#!/bin/bash
source /root/bin/boot-scala.sh
!#
import java.io.File
import utils.Timer
object App {
def main(args: Array[String]): Unit = {
val timer = new Timer
timer.start
println("Executing '%s' in directory '%s'".format(args(1), args(0)))
println("There are %d arguments passed to script.".format(args.length))
println(args.mkString(" "))
println("Time elapsed: " + timer.elapsed)
As you can see in boot-scala.sh, I am extracting SCRIPT name and DIR name and then these values are passed to scala.
Problem is that I can only provide classpath to scala tool, so I have to compile manually my scala-utils.scala file and put classes into arbitrary /tmp/scala-cp.
If scala tool could have another command line argument e.g. -sources, then I could provide other files directly without making such a strange hacks.
Also it would be nice if compiled *.jar files could be stored in some internal scala directory, so they are not cluttering my scripts directory.
The text was updated successfully, but these errors were encountered:
'scala' command line tool is very useful as a linux script executor. Unfortunately it supports only one file which, can be passed as argument. But I think that in more advance system scripting it is very common to want to refactor part of scripts into separate source unit. For example I have few scripts in bash for backing up my system, but calculating paths is common part and is in separate file mirror-config.sh.
As I said before I can not do it easily using Scala as I can not provide more than one scala source file.
My current (imperfect) solution is as follows:
scala-utils.scala -> contains some common utilities for scripting
test.sh -> main script in scala wrapped in bash
test.sh file:
#!/bin/bash
source /root/bin/boot-scala.sh
!#
import java.io.File
import utils.Timer
object App {
def main(args: Array[String]): Unit = {
val timer = new Timer
}
}
boot-scala file:
#!/bin/sh$SCRIPT $ @
SCRIPT="$(cd "${0%/}" 2>/dev/null; echo "$PWD"/"${0##/}")"
DIR=
dirname "${SCRIPT}"}
CP="/tmp/scala-cp/"
if [ ! -d $CP ]; then
mkdir /tmp/scala-cp
scalac -d $CP $DIR/*.scala
fi
exec scala -savecompiled -classpath $CP $0 $DIR
As you can see in boot-scala.sh, I am extracting SCRIPT name and DIR name and then these values are passed to scala.
Problem is that I can only provide classpath to scala tool, so I have to compile manually my scala-utils.scala file and put classes into arbitrary /tmp/scala-cp.
If scala tool could have another command line argument e.g. -sources, then I could provide other files directly without making such a strange hacks.
Also it would be nice if compiled *.jar files could be stored in some internal scala directory, so they are not cluttering my scripts directory.
The text was updated successfully, but these errors were encountered: