This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.4, “How to run a shell command from the Scala REPL.”
You want to be able to run a shell command from within the Scala REPL, such as listing the files in the current directory.
Run the command using the
:sh REPL command, then print the output. The following example shows how to run the Unix
ls -al command from within the REPL, and then show the results of the command: