Files
luash/examples/03_interpolation.luash
2025-08-29 01:06:03 +01:00

32 lines
1.0 KiB
Plaintext

#!/usr/bin/env luash
-- Variable Interpolation Demo
print("=== Variable Interpolation in Shell Commands ===\n")
print("1. Basic variable interpolation:")
service = "ssh"
result = `pgrep #{service} | wc -l`
print(" Processes named '" .. service .. "': " .. result)
print("\n2. Multiple variables in one command:")
dir = "/tmp"
pattern = "*.log"
files = `find #{dir} -name #{pattern} 2>/dev/null | wc -l`
print(" Files matching '" .. pattern .. "' in " .. dir .. ": " .. files)
print("\n3. Network connectivity check:")
host = "google.com"
ping_result = `ping -c 1 #{host} >/dev/null 2>&1 && echo "ok" || echo "fail"`
print(" " .. host .. " is " .. (ping_result == "ok" and "reachable" or "unreachable"))
print("\n4. Dynamic file operations:")
filename = "README.md"
if `test -f #{filename}` ~= "" then
lines = `wc -l < #{filename}`
print(" " .. filename .. " has " .. lines .. " lines")
else
print(" " .. filename .. " not found")
end
print("\n✨ Use #{variable} syntax to substitute Lua variables into shell commands!")