This is a friendly comparison of the syntax of different shells!
oil | shpp | |
source |
# oil requires quotes
echo 'hello world'
const name = 'world'
echo "hello $name"
|
# no single quotes echo hello world name = "world" echo "hello ${name}" # braces required |
output | hello world hello world |
hello world hello world |
oil | shpp | |
source | if test --exists /bin/grep { echo 'file exists' } |
if path("/bin/grep").exists() { echo "file exists" } |
output | file exists |
file exists |
oil | shpp | |
source | ls src* | sort -r | head -n 3 |
ls src* | sort -r | head -n 3 |
output | src5 src4 src3 |
./src5 ./src4 ./src3 |
oil | shpp | |
source | echo hello | read --line # _line starts with _, so it's a # "register" mutated by the interpreter echo "line: $_line" |
# not sure how to feed stdin
line = read()
print("line: ", line)
|
output | line: hello |
line: [null] |
oil | shpp | |
source |
# TODO: Oil could expose strerror() like shpp
try zzz
if (_status === 127) {
echo "zzz not installed"
}
|
try { zzz } catch InvalidCmdException as ex { print("zzz not installed [msg: ", ex, "]") } |
output | zzz not installed |
zzz not installed [msg: zzz: No such file or directory] |
oil | shpp | |
source | const array1 = ['physics', 'chemistry', 1997, 2000] const array2 = [1, 2, 3, 4, 5, 6, 7] write -- "array1[0]: $[array1[0]]" # TODO: Oil needs @[] const slice = array2[1:5] write -- "array2[1:5]" @slice # use the word language: bare words, glob, brace expansion const shell_style = %( README.md *.py {alice,bob}@example.com ) write -- @shell_style |
array1 = ["physics", "chemistry", 1997, 2000]; array2 = [1, 2, 3, 4, 5, 6, 7 ]; print("array1[0]: ", array1[0]) print("array2[1:5]: ", array2[1:5]) |
output | array1[0]: physics array2[1:5] 2 3 4 5 README.md bar.py foo.py alice@example.com bob@example.com |
array1[0]: physics array2[1:5]: [2, 3, 4, 5] |