The Problem
Amber is a modern programming language that compiles to Bash, designed to make shell scripting safer and more maintainable. The stdlib was missing common system utility functions that developers needed for everyday tasks like getting system info, managing processes, and manipulating text.
Issue #951 requested these utilities to reduce the need for raw Bash fallbacks.
The Solution
I implemented 24 new stdlib functions across two modules, following Amber’s design principles of type safety and clean syntax.
System Information (src/std/env.ab)
// Get system details
let kernel = uname_kernel_name() // "Linux"
let host = uname_nodename() // "myserver"
let all = uname_all() // Full uname output
Functions added:
uname_kernel_name(),uname_nodename(),uname_kernel_release(),uname_kernel_version(),uname_machine(),uname_os(),uname_all()
Process Management (src/std/env.ab)
// Find and kill processes
let pids = pgrep("nginx") // Get PIDs matching pattern
pkill_exact("zombie-process") // Kill exact match
kill(1234, "SIGTERM") // Send signal to PID
Functions added:
pgrep(),pgrep_exact()- process discovery using native Amber loopspkill(),pkill_exact(),pkill_force()- process terminationkill()- send arbitrary signals to PIDs
Filesystem Operations (src/std/env.ab)
// Mount with sudo modifier
sudo mount("/dev/sdb1", "/mnt/usb")
sudo umount("/mnt/usb")
Functions added:
mount(),umount(),umount_force()- withsudomodifier support
Text Processing (src/std/text.ab)
let text = "hello\nworld\nhello"
let count = lines_count(text) // 3
let sorted = sort_lines(text) // Alphabetically sorted
let unique = uniq_all_lines(text) // Deduplicated
Functions added:
lines_count(),words_count(),chars_count()sort_lines(),sort_lines_desc(),sort_lines_numeric()uniq_lines(),uniq_all_lines()
Files Changed
| File | Changes |
|---|---|
src/std/env.ab | +15 functions for system/process operations |
src/std/text.ab | +9 functions for text processing |
src/tests/validity/*.ab | 17 test files with comprehensive coverage |
Review Process
The PR went through multiple iterations based on maintainer feedback from @Ph0enixKM and @Tirito6626:
- Native Amber over Bash: Converted
whileloops to native Amberloopconstructs - Here-string syntax: Adopted cleaner syntax over
printfpipes - v0.6.0 compatibility: Updated
echosyntax to match new language version - Sudo modifier: Added proper
sudosupport for mount operations
Timeline
| Date | Event |
|---|---|
| 2025-12-18 | Implemented all functions and tests |
| 2025-12-19 | Addressed review feedback, converted to native Amber patterns |
| 2025-12-19 | Added kill() function, updated to v0.6.0 syntax |
| 2025-12-21 | PR reworked and merged via #965 |