Learn Elvish - 10 Code Examples & CST Typing Practice Test
Elvish is a modern, expressive shell and scripting language designed for interactive use and automation. It emphasizes structured data, pipelines, modularity, and user-friendly syntax, combining features from traditional Unix shells with modern programming concepts.
Learn ELVISH with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Elvish Counter and Theme Toggle
count = 0
isDark = $false
fn updateUI {
echo "Counter: $count"
if $isDark {
echo "Theme: Dark"
} else {
echo "Theme: Light"
}
}
fn increment {
count = (math $count + 1)
updateUI
}
fn decrement {
count = (math $count - 1)
updateUI
}
fn reset {
count = 0
updateUI
}
fn toggleTheme {
isDark = (not $isDark)
updateUI
}
# Simulate actions
updateUI
increment
increment
toggleTheme
decrement
reset
Demonstrates a simple counter with theme toggling using Elvish variables and functions.
Elvish Fibonacci Sequence
a = 0
b = 1
echo $a
echo $b
for i (1 2 3 4 5 6 7 8) {
c = (math $a + $b)
echo $c
a = $b
b = $c
}
Generates the first 10 Fibonacci numbers.
Elvish Factorial Calculator
fn fact [n]{
if (math $n == 0) {
return 1
} else {
return (math $n * (fact (math $n - 1)))
}
}
echo (fact 5)
Calculates factorial of a number recursively.
Elvish Prime Checker
fn isPrime [n]{
if (math $n < 2) { return $false }
for i (2..(math $n - 1)) {
if (math $n % $i == 0) { return $false }
}
return $true
}
echo (if (isPrime 13) {"Prime"} else {"Not Prime"})
Checks if a number is prime.
Elvish Sum of List
lst = [1 2 3 4 5]
sum = 0
for x $lst {
sum = (math $sum + $x)
}
echo $sum
Calculates sum of a list of numbers.
Elvish Multiplication Table
n = 5
for i (1..10) {
echo (str $n " x " $i " = " (math $n * $i))
}
Prints multiplication table of a number.
Elvish Celsius to Fahrenheit
c = 25
f = (math ($c * 9 / 5) + 32)
echo $f
Converts Celsius to Fahrenheit.
Elvish Simple Alarm Simulation
temp = 80
thresh = 75
echo (if ($temp > $thresh) {"Alarm: Temperature Too High!"} else {"Temperature Normal"})
Simulates an alarm if a threshold is exceeded.
Elvish Random Walk Simulation
steps = 10
pos = 0
for i (1..$steps) {
if (random 1 < 0.5) {
pos = (math $pos + 1)
} else {
pos = (math $pos - 1)
}
echo $pos
}
Simulates a 1D random walk.
Frequently Asked Questions about Elvish
What is Elvish?
Elvish is a modern, expressive shell and scripting language designed for interactive use and automation. It emphasizes structured data, pipelines, modularity, and user-friendly syntax, combining features from traditional Unix shells with modern programming concepts.
What are the primary use cases for Elvish?
Interactive shell for Unix/Linux systems. Automation scripts for system tasks. Structured data pipelines and processing. Custom command extensions. Rapid prototyping of shell scripts
What are the strengths of Elvish?
More expressive than traditional shells like Bash or Zsh. Supports structured data natively in pipelines. Interactive features for productivity. Extensible with custom modules. Modern scripting for system automation
What are the limitations of Elvish?
Smaller ecosystem compared to Bash/Zsh. Learning curve for users familiar with traditional shells. Limited adoption in enterprise environments. Not pre-installed on most systems. Some older shell scripts may need rewriting
How can I practice Elvish typing speed?
CodeSpeedTest offers 10+ real Elvish code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.