watch ppt demo#
- Basic Concept Comparison
| Concept | Bash Syntax | Lumesh Syntax | Description |
|---|---|---|---|
| Interpreter Declaration | #!/bin/bash | #!/usr/bin/env lumesh | Lumesh recommends using the env method to call |
| Comment | # comment content | # comment content | Same as Bash |
| Line Continuation | \ | \ | Same as Bash, but no continuation character needed inside strings |
- Variable Operation Comparison
| Operation | Bash Syntax | Lumesh Syntax | Description |
|---|---|---|---|
| Variable Declaration | var=value | let var = value | Spaces are optional; must declare in strict mode |
| Variable Reference | $var or ${var} | $var or directly var | $ is optional; must use $ in strict mode |
| Multiple Variable Declaration | Not supported | let a, b = 1, 2 | |
| Delete Variable | unset var | del var | |
| Lazy Assignment | Not supported | x := 2 + 3 | |
| Type Check | Not supported | type var == "Integer" |
- Data Type Comparison
| Type | Bash Handling | Lumesh Syntax | Description |
|---|---|---|---|
| Integer | declare -i var=10 | let var = 10 | Automatically assigns type |
| Float | Not supported | let var = 10.0 | |
| String | str="hello" | let str = "hello" | |
| Array | arr=(1 2 3) | let arr = [1, 2, 3] or 1...<3 | |
| Dictionary | declare -A dict=([k]=v) | let dict = {k: v} | |
| Range | {1..10} | 1..10 or 1..<10 | Basic data type, can participate in calculations |
| File Size | String | 200M | Basic data type, can participate in calculations |
| Time | String | Fs.parse('2025-10-1') | Basic data type, can participate in calculations |
- Operator Comparison
| Operator | Bash Syntax | Lumesh Syntax | Description |
|---|---|---|---|
| Arithmetic | $((a + b)) | a + b | Direct calculation |
| String Concatenation | "$a$b" | a + b or format("a={}",a) | format is an alias for String.format |
| Equality Check | [ "$a" == "$b" ] | a == b or a ~= b | Cross-type comparison with ~= |
| Inclusion Check | [[ "str" =~ "pattern" ]] | str ~: 'pattern' | Inclusion operation can be used for arrays, ranges, dictionaries, and strings |
| Regex Match | [[ "str" =~ "regex" ]] | str ~~ 'regex' | Has regex library available |
- Control Flow Comparison
| Structure | Bash Syntax | Lumesh Syntax | Description |
|---|---|---|---|
| if Statement | if [ cond ]; then ... fi | if cond {...} else {...} | |
| for Loop | for i in {1..3}; do ... done | for i in 1..3 {...} | |
| while Loop | while [ cond ]; do ... | while cond {...} | |
| case Statement | case $var in ... esac | match var {...} | Match statement |
| repeat Loop | No direct equivalent | repeat 10 {...} | Repeat loop, an alias for List.map |
| each Loop | No direct equivalent | each {} [1..3] | An alias for List.map |
- Function Comparison
| Feature | Bash Syntax | Lumesh Syntax | Description |
|---|---|---|---|
| Function Definition | func() { cmds; } | fn func() {...} | |
| Anonymous Function | None | let f = (x,y) -> x + y | Lambda expression |
| Function Parameters | func() { $1,$2... } | fn func(a,b) { a,b...} | Parameter list |
| Default Parameters | Not supported | fn f(a=1) {...} | Default parameters |
| Rest Parameters | "$@" | fn f(*args) {...} | Collects rest parameters |
| Function Call | func a1 | func(a1) or func! a1 | |
| Higher-order Function | Not directly supported | funcA(funcB) | Function as a parameter |
| Scope | Only supports global scope | Functions have isolated scope |
- System Command Comparison
| Operation | Bash Syntax | Lumesh Syntax | Description |
|---|---|---|---|
| Command Execution | cmd | cmd | |
| Background Run | cmd & | cmd & | |
| Close Output | cmd >/dev/null | cmd &- | |
| Close Error | cmd 2>/dev/null | cmd &? | |
| Pipe | `cmd1 | cmd2` | `cmd1 |
| Redirect Append | cmd >> file | cmd >> file | Same as Bash |
| Redirect Overwrite | cmd > file | cmd >! file |
- Advanced Feature Comparison
| Feature | Bash Support | Lumesh Support | Description |
|---|---|---|---|
| Implicit Type Conversion | No | Automatically converts numbers and strings | |
| Operator Overloading | No | Supports various types of addition, subtraction, multiplication, and division | |
| Matrix Operations | No | Supports matrix multiplication | |
| Error Messages | Rough | Detailed | Will provide line numbers, context, and error types |
| Error Handling | Only $? status code detection | Supports exception capture, ignore, print, etc. | More convenient exception handling mechanism |
| Interactive Mode | Supported | Syntax highlighting, auto-completion, AI assistance, key bindings | Enhanced REPL interactive mode |
| Built-in Libs | No | Built-in many useful functions | See Libs |
| Structured Pipeline | No | Supports `Into | where |
- Migration Suggestions
Variable Declaration: Keep
var=valueas is; in strict mode, change the first declaration tolet var = value.Conditional Judgment: Change from
[ "$a" == "$b" ]toa == bor$a == $b.Loop Statements: Change from
for i in {1..10}tofor i in 1..10.Function Definition: Change from
func() {...}tofn func() {...}.Error Handling: Keep
cmd || fallbackas is or change tocmd ?: fallback.Notes
Lumesh's array indexing starts from 0 (same as Bash).
The range expression
a..<bdoes not includeb, whilea..bincludesb.Function calls require
()or!suffix.In strict mode, the
$prefix must be used to reference variables.Operator precedence differs from Bash.
Learning Resources
- Official Documentation: Lumesh Syntax Manual
- Interactive Tutorial: Run
lumeshto enter REPL mode for practice.