#!/usr/bin/swift import Foundation func shell(_ command: String) { let task = Process() task.launchPath = "/bin/zsh" task.arguments = ["-c", command] let pipe = Pipe() task.standardOutput = pipe task.launch() let data = pipe.fileHandleForReading.readDataToEndOfFile() let output = String(data: data, encoding: .utf8) ?? "" print(output) } shell("export MY_VAR=123 ; echo $MY_VAR") // In CLI: // chmod a+x Shell.swift // ./Shell.swift