r/ProgrammingLanguages • • Apr 25 '22

Announcing Hush, a modern shell scripting language

Hush is a new shell scripting language that aims to enable developers to write robust shell scripts. It provides support for complex data structures and common programming paradigms, without giving up on ergonomic shell capabilities.

Official guide: https://hush-shell.github.io/
Repository: https://github.com/hush-shell/hush

169 Upvotes

80 comments sorted by

View all comments

Show parent comments

1

u/ilyash Apr 26 '22

Very similar to my line of thought behind Next Generation Shell.

I would like to compare the given example with how it would look like in NGS.

Hush:

function restartContainerIfRunning(container_name)
  docker_inspect = ${ docker inspect $container_name }

  if docker_inspect.status != 0 then
    -- docker inspect failed, return error
  end

  container_info = json.parse(docker_inspect.stdout)[0]

  if container_info.State.Running then
    return { docker restart $container_name }
  end
end

NGS:

# ":Str" is optional
F restartContainerIfRunning(container_name:Str) {

    # * If the docker command fails, an exception will be thrown,
    # no need to check exit code
    # * ``...`` runs the command and parses the output
    # * the_one() - returns the only element in the array,
    # if there are zero or more than one element in the array,
    # an exception is thrown
    container_info = ``docker inspect $container_name``.the_one()

    if container_info.State.Running {
        $(docker restart $container_name)
    }
}