process

How to process every line in a file with a Unix/Linux shell script

Unix/Linux shell script FAQ: How do I write a Unix or Linux shell script where I "do something" for every line in a text file?

Solution: An easy way to process every line in a text file is to use a Unix/Linux while loop in combination with the Linux cat command, like this:

How to run external shell commands in SBT (Simple Build Tool)

To run external shell commands in SBT, first start SBT from your operating system command line:

$ sbt

Then run the consoleProject task/command:

> consoleProject

After some output you’ll see this prompt:

scala>

Now you can execute shell commands by including them in double quotes, and following them by an exclamation mark, like this:

scala> "ls -al" !

For more information, see the SBT consoleProject documentation page.

How to run shell commands from the Scala REPL

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.”

Problem

You want to be able to run a shell command from within the Scala REPL, such as listing the files in the current directory.

Solution

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:

Process, not results

There’s a well-known sports psychologist in Denver who tells people to feel less stress by focusing on process, not the results of the process. I suspect that’s where this Adam Gase quote comes from:

“We’re just trying to get players better, rather than worrying about the result. We follow our process, and whatever the outcome ends up being, well, it’s been good in the past.”

Scala - An index of methods to run/execute external system commands

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.20, “An index of methods available to run external system commands.”

The following tables list the methods of the scala.sys.process package that you can use when running external (system) commands.

Methods to execute external commands

Table 12-1 lists the methods that you can use to execute system commands.

Table 12-1. Methods to execute system commands

Scala: How to set environment variables when running external commands

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 12.19, “How to set environment variables when running external commands.”

Problem

You need to set one or more environment variables when running an external command.

Solution

Specify the environment variables when calling a Process factory method (an apply method in the Process object).

Scala: How to run an external command (process) in a different directory

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a very short recipe, Recipe 12.18, “How to run an external command (process) in a different directory.”

Problem

You want to use another directory as the base directory when running an external command.

Scala: How to handle wildcard characters when running external commands

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.17, “How to handle wildcard characters when running external commands.”

Problem

You want to use a Unix shell wildcard character, such as *, in an external command.