Exiting Spark-shell from the scala script

I am using this command to run scala scripts.

spark-shell -i test.scala

At the end of the execution of the script I still see spark-shell running.

I have used ":q/:quit" in the test.scala script to try and exit but it's not working.

In version 2.4.3 System.exit(0) is working.

You need to add exit() at the end of your script to avoid stepping into scala REPL.


print("Hello World");
print("Second Line");
print("Bye now");

Run above

spark-shell -i helloworld.scala

I also like the echo :quit | spark-shell ... answer that was offered on another question.