Shell/Dreams

Материал из Etersoft wiki
Перейти к навигацииПерейти к поиску

Dreams about new generation Bash syntax

  1. Backward compatible with bash code (like C++ compilers supports C)
  2. Use static analizer like shellcheck by default
  3. Use shellcheck extension for VS Code
  4. Use shell formatter shfmt (https://github.com/mvdan/sh)
  5. Use transpiler
  6. Modules support

Исследование, что имеется: Shell/Reload.

Features

  • indentbased, memorizable, coffeescript-inspired syntax
  • removes semantic noise like { ! @ || ~=
  • safetynets: automatic quoting, halt on error or missing dependency (require_cmd)
  • comfort: json, easy arrays, easy async, functional programming, named variables instead of positionals
  • Modules / bundling

https://github.com/coderofsalvation/powscript

Use vars without quotes

Drop any qoute hell: make qoute arg optionally.

if [ $1 = "Hello" ]

always correct, ever when $1 is empty


Function arguments

[function] funcname(arg1, arg2) {
    echo "First arg: $arg1, Secord arg: $arg2"
}

funcname "Hello" "second!"

Global and local variables

All vars are local by default.

use global [readonly] varname for define global var;


Function return value

funcname(arg1) {
    return "text: $arg1"
}

$str = $(funcname Hello)


funcname(arg1) {
    [ "$arg1" = "Hello" ]
}

funcname Hello || echo Bye

if

Use usual

if ($a > $b)
if ($a == $b)

arithmetics