Skip to content

Commands and Exit Status

Chloë Strainge edited this page Oct 14, 2026 · 1 revision

Commands and exit status

At command position, Shelly resolves language functions and then external programs. Arguments such as diff in git diff are ordinary words. Group an invocation to execute it inside an argument: git (diff).

Resolve a command deliberately

::name bypasses interpreter definitions and searches for an external program. Paths such as /usr/bin/printf also identify programs directly.

fn printf($message: String): String { "wrapped: ${message}" }
echo (printf "hello")
::printf '%s\n' "external hello"
wrapped: hello
external hello

A bare word initializing a variable is executed: let $result = task. task must resolve at runtime. Quote it to store text, or use a backtick reference to retain a validated callable without invoking it. See Functions.

Status is not stdout

ExecResult describes an external program's completion. Code zero is true; nonzero codes and signal termination are false. A function's returned Boolean uses ordinary Boolean truth instead.

let $result = /usr/bin/false
if $result { echo "completed" } else { echo "not completed" }
echo $result
not completed
ExecResult(1)

Here /usr/bin/false is an external utility. The Boolean literal is false in expression position; an unambiguous comparison or a typed value can be used when needed. A captured status is handled by the script. An uncaptured failed command aborts that execution; the REPL reports it and accepts another command.

Built-ins such as cd and exit affect Shelly itself. A child program cannot change its parent's working directory. Use exit N to choose an explicit script exit code.

Aliases and arguments

alias heading = echo "Dispatch:"
heading "northbound"
Dispatch: northbound

Aliases provide command-name shortcuts with literal default arguments. They are expanded at command lookup, and alias cycles are rejected. They do not replace functions for calculations or structured data processing. Syntax reference shows their declaration form.

Globs and argument spreading are separate: an unquoted glob selects filesystem paths, while $items... supplies array items as separate arguments. Quote a glob when the program itself should interpret it.


Related: Running Shelly · Redirection · Pipelines

Clone this wiki locally