wow
This commit is contained in:
40
demos/basic.luash
Normal file
40
demos/basic.luash
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env luash
|
||||
-- Basic Luash Demo: Environment Variables and Shell Commands
|
||||
|
||||
print("=== Basic Luash Features ===\n")
|
||||
|
||||
-- Environment variable access (clean syntax)
|
||||
print("1. Environment Variables:")
|
||||
print(" User: " .. $USER)
|
||||
print(" Shell: " .. $SHELL)
|
||||
print(" Home: " .. $HOME)
|
||||
|
||||
-- Environment variable assignment
|
||||
print("\n2. Setting Environment Variables:")
|
||||
$MY_VAR = "Hello from Luash!"
|
||||
print(" Set MY_VAR = " .. $MY_VAR)
|
||||
|
||||
-- String literals preserve $ symbols
|
||||
print("\n3. Strings preserve $ literals:")
|
||||
print(" This prints literally: $USER and $HOME are variables")
|
||||
|
||||
-- Shell command execution with backticks
|
||||
print("\n4. Shell Commands:")
|
||||
hostname = `hostname`
|
||||
print(" Hostname: " .. hostname)
|
||||
|
||||
date_info = `date +"%Y-%m-%d %H:%M:%S"`
|
||||
print(" Current time: " .. date_info)
|
||||
|
||||
-- Interactive commands for direct output
|
||||
print("\n5. Interactive Commands:")
|
||||
print(" Directory listing:")
|
||||
!ls -la
|
||||
|
||||
print("\n6. Combining Lua logic with shell:")
|
||||
files = `ls -1`
|
||||
file_count = 0
|
||||
for line in files:gmatch("[^\n]+") do
|
||||
file_count = file_count + 1
|
||||
end
|
||||
print(" Found " .. file_count .. " files in current directory")
|
||||
Reference in New Issue
Block a user