MirBSD Korn Shell
2002fragletshellimperativescripting.mksh
docker run --rm --platform="linux/amd64" 100hellos/mksh:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →mksh
A free implementation of the Korn shell. Like bash, this is a superset of the Bourne Shell.
Hello World
#!/usr/bin/env mksh
print "Hello World!"Coding Guide
Language Version
mksh (MirBSD Korn Shell) - Korn shell implementation
Execution Model
- Interpreted shell script
- Code executes directly from source
- Scripts run line-by-line from top to bottom
- Uses shebang
#!/usr/bin/env mkshfor execution - Compatible with POSIX shell and extends Korn shell features
Key Characteristics
- Korn shell compatible (superset of Bourne Shell)
- Case-sensitive
- Variables:
VAR=value(no spaces around=) - Command substitution:
`command`or$(command) - String interpolation:
"$VAR"or"${VAR}" - Arrays:
set -A ARRAY item1 item2 item3 - Arithmetic expansion:
$((expression)) - Pattern matching:
[[ string =~ pattern ]](Korn shell style) - Uses
printcommand (Korn shell style) instead ofecho
Fragment Authoring
Write valid mksh shell commands. Your fragment becomes the script body. The fragment code will execute as part of the shell script.
Fragments are injected at the point where print "Hello World!" appears, so you can replace the print statement or add additional commands.
Available Commands
Standard Unix utilities and mksh built-ins are available:
print- Print text (Korn shell style)echo- Print text (POSIX style, also available)printf- Formatted outputtest/[/[[- Conditional testsif,while,for,until- Control structuresgrep,sed,awk- Text processing- Standard Unix utilities
Common Patterns
- Output:
print "message"orecho "message"orprintf "%s\n" "message" - Variables:
NAME="value"andprint "$NAME" - Arrays:
set -A ARRAY item1 item2 item3andprint "${ARRAY[@]}" - Conditionals:
if [[ condition ]]; then ... fi - Loops:
for i in 1 2 3 4 5; do print "$i"; doneorfor i in $(seq 1 5); do print "$i"; done - Command substitution:
RESULT=$(command) - Arithmetic:
$((A + B))orlet "result = A + B" - Functions:
function_name() { ... } - Here documents:
cat <<EOF ... EOF
Examples
# Simple output
print "Hello from fragment!"
# Variables
NAME="Alice"
print "Hello, $NAME!"
# Arithmetic
A=5
B=10
SUM=$((A + B))
print "Sum: $SUM"
# Arrays
set -A FRUITS apple banana cherry
for fruit in "${FRUITS[@]}"; do
print "Fruit: $fruit"
done
# Conditionals
if [[ "test" == "test" ]]; then
print "Testing mode"
else
print "Normal mode"
fi
# Functions
greet() {
local name="$1"
print "Hello, $name!"
}
greet "World"
# Command substitution
DATE=$(date)
print "Current date: $DATE"
# Arithmetic loops (using seq)
for i in $(seq 1 5); do
print "Count: $i"
done
# Multiple statements
print "First line"
print "Second line"
print "Third line"
# Nested conditionals
if [[ -n "$1" ]]; then
if [[ "$1" == "hello" ]]; then
print "Greeting received"
else
print "Other argument: $1"
fi
else
print "No argument provided"
fiCaveats
- Variable assignment: no spaces around
= - Use
[[for Korn shell-specific tests,[for POSIX compatibility - Quote variables to prevent word splitting:
"$VAR" - Arrays use
set -Asyntax:set -A ARRAY item1 item2 item3 - Array access:
"${ARRAY[@]}"for all elements,"${ARRAY[0]}"for first element - Case-sensitive variable names
- Arithmetic expansion:
$((expression))(no$inside) - Function definitions:
function_name() { ... }orfunction function_name { ... } - Use
localkeyword inside functions to avoid global variable pollution - Prefer
printoverechofor Korn shell style (thoughechoalso works) - Brace expansion like
{1..5}does NOT work in mksh (use explicit lists orseq)
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=mksh
echo "Args: $*"Mksh Fortune
#!/usr/bin/env -S fragletc --vein=mksh
# One from the vault: mksh fortunes
print "mksh: the shell that proves you can be small, fast, and POSIX at the same time."Stdin Upper
#!/usr/bin/env -S fragletc --vein=mksh
while read -r line; do echo "$line" | tr "a-z" "A-Z"; doneTest
#!/usr/bin/env -S fragletc --vein=mksh
print "Hello World!"Connections
influenced by