#!/usr/bin/env luash -- Luash Showcase: Highlight the best features print("šŸš€ Luash - Minimal Lua Shell Scripting") print("=" .. string.rep("=", 45)) print("\nšŸ’” Why Luash?") print("āœ“ Clean syntax - no more bash quoting nightmares") print("āœ“ Real programming language features") print("āœ“ Seamless shell integration") print("āœ“ Minimal and focused") print("\nšŸ“Š Quick Comparison:") print("ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”") print("│ Task │ Bash │ Luash │") print("ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤") print("│ Variables │ VAR=\"value\" │ $VAR = \"value\" │") print("│ Command Sub │ result=$(cmd) │ result = `cmd` │") print("│ Conditionals │ if [ -f file ]; fi │ if `test -f file` │") print("│ Arrays │ arr=(a b c) │ arr = {\"a\",\"b\",\"c\"} │") print("│ Functions │ Limited │ Full Lua functions │") print("ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜") print("\nšŸŽÆ Live Examples:") print("\n1. Environment & Variables") print(" Current user: " .. $USER) $GREETING = "Hello from Luash" print(" Custom var: " .. $GREETING) print("\n2. Shell Integration") system_info = `uname -a` print(" System: " .. system_info) file_count = `ls | wc -l` print(" Files here: " .. file_count) print("\n3. Real Programming") -- Lua's power: functions, tables, proper data types function analyze_directory(path) local files = `ls -la ` .. (path or ".") local lines = {} local file_count = 0 local total_size = 0 for line in files:gmatch("[^\n]+") do if not line:match("^total") and not line:match("^d") then file_count = file_count + 1 -- Extract size (5th field in ls -la) local size = line:match("%S+%s+%S+%s+%S+%s+%S+%s+(%d+)") if size then total_size = total_size + tonumber(size) end end end return file_count, total_size end files, size = analyze_directory() print(" Analysis: " .. files .. " files, " .. size .. " bytes total") print("\n4. Error Handling") if `which git 2>/dev/null` ~= "" then print(" āœ“ Git is available") if `git status 2>/dev/null` ~= "" then branch = `git branch --show-current 2>/dev/null` print(" Current branch: " .. branch) else print(" Not in a git repository") end else print(" āœ— Git not installed") end print("\n5. Data Processing") -- Create and process some data sample_data = { {name = "Alice", score = 95}, {name = "Bob", score = 87}, {name = "Charlie", score = 92} } total_score = 0 for i = 1, #sample_data do total_score = total_score + sample_data[i].score end average = total_score / #sample_data print(" Student scores processed:") print(" Average: " .. string.format("%.1f", average)) -- Find highest scorer best_student = sample_data[1] for i = 2, #sample_data do if sample_data[i].score > best_student.score then best_student = sample_data[i] end end print(" Top student: " .. best_student.name .. " (" .. best_student.score .. ")") print("\nšŸŽŖ Interactive Demo:") print(" Let's see what's running on your system...") !ps aux | head -5 print("\nšŸ“ˆ Performance:") start_time = `date +%s.%N` -- Simulate some work for i = 1, 1000 do local _ = string.upper("performance test " .. i) end end_time = `date +%s.%N` -- Calculate duration (requires bash-style arithmetic) duration = tonumber(end_time) - tonumber(start_time) print(" Processed 1000 operations in " .. string.format("%.3f", duration) .. " seconds") print("\n✨ Try these demos:") print(" ./luash demo_quick_examples.luash # Side-by-side with bash") print(" ./luash demo_system_admin.luash # Sysadmin tasks") print(" ./luash demo_development.luash # Dev workflows") print(" ./luash demo_data_processing.luash # Data analysis") print("\nšŸŽ‰ Luash: Shell scripting that doesn't make you cry!")