You can execute arbitrary shell commands by calling shellOut(). You can pass a single command string or an array of command strings to run multiple commands sequentially. You can also specify a working directory using the at: parameter.
If a command fails, ShellOut throws a ShellOutError which contains the message (the content of STDERR) and the output (the content of STDOUT).
// Run a single command with arguments
let output = try shellOut(to: "echo", arguments: ["Hello world"])
print(output) // Hello world
// Run multiple commands at a specific path
try shellOut(to: ["mkdir NewFolder", "echo \"Hello again\" > NewFolder/File"], at: "~/CurrentFolder")
let output = try shellOut(to: "cat File", at: "~/CurrentFolder/NewFolder")
print(output) // Hello again
// Error handling
do {
try shellOut(to: "totally-invalid")
} catch {
let error = error as! ShellOutError
print(error.message) // Prints STDERR
print(error.output) // Prints STDOUT
}