var a = 375
set a = 376
var hello = $a
echo $E:HOME
echo $E:USER
> elvish -c "echo $args"
[]
> elvish -c "echo $args" 1 2 3
[1 2 3]
> elvish -c "echo $args" --path /path/to -v
[--path /path/to -v]
> elvish -c "echo $args[0]" --path /path/to -v
--path
> elvish -c "count $args" --path /path/to -v
▶ (num 3)
- $true
- $false
- $nil
if <condition> {
<body>
} elif <condition> {
<body>
} else {
<else-body>
}
for <var> <container> {
<body>
} else {
<body>
}
ls
var out = (ls)
try {
}
catch {
}
if ?(test -d name) {
}
fn <name> <lambda>
range 1 10 | peach {|x| + $x 10 }
Here is the Scala equiv:
(1 to 10).par.foreach(x => x + 10)
Elvish is an expressive programming language and a versatile interactive shell, combined into one seamless package. It runs on Linux, BSDs, macOS and Windows.
I'm using Elvish 0.19.2, and Elvish is implemented in Go.
- Concise
- Cross Platform: GNU coreutils
- Windows
- macOS/Linux
- Versatile expression
- e.g. String manipulation in Bash Scripting is extremely hard
Shell Scripting:
rm -rf .git/
Python:
import subprocess
subprocess.call(["rm", "-rf", ".git/"])
Sample 1
all [ 1 2 3 4 5 ] | each {|x|
+ $x 1
}
Sample 2
all [ 1 2 3 4 5 ] | each {|x|
+ $x 1
} | each {|x|
+ $x 2
}
Sample 3
each {|x| + $x 1} [1 2 3 4 5]
fn filter {|pred @rest|
each {|x|
if ($pred $x) {
put $x
}
} $@rest
}
put 1 2 3 args each | each { |x|
put $x.elv
} | filter { |file_name|
if ?(test -f $file_name) { put $true } else { put $false }
} | each { |x|
echo $x
}