Files
lux/examples/shell.lux
2026-02-17 06:52:44 -05:00

44 lines
1.4 KiB
Plaintext

fn main(): Unit with {Process, Console} = {
Console.print("=== Lux Shell Example ===")
Console.print("")
let cwd = Process.cwd()
Console.print("Current directory: " + cwd)
Console.print("")
Console.print("Environment variables:")
match Process.env("USER") {
Some(user) => Console.print(" USER: " + user),
None => Console.print(" USER: (not set)"),
}
match Process.env("HOME") {
Some(home) => Console.print(" HOME: " + home),
None => Console.print(" HOME: (not set)"),
}
match Process.env("SHELL") {
Some(shell) => Console.print(" SHELL: " + shell),
None => Console.print(" SHELL: (not set)"),
}
Console.print("")
Console.print("Running shell commands:")
let date = Process.exec("date")
Console.print(" date: " + String.trim(date))
let kernel = Process.exec("uname -r")
Console.print(" kernel: " + String.trim(kernel))
let files = Process.exec("ls examples/*.lux | wc -l")
Console.print(" .lux files in examples/: " + String.trim(files))
Console.print("")
Console.print("Command line arguments:")
let args = Process.args()
let argCount = List.length(args)
if argCount == 0 then {
Console.print(" (no arguments)")
} else {
Console.print(" Count: " + toString(argCount))
match List.head(args) {
Some(first) => Console.print(" First: " + first),
None => Console.print(" First: (empty)"),
}
}
}
let result = run main() with {}