Repository navigation
Language Basics
A Shelly program is a sequence of statements. Newlines and semicolons separate them. Braces group statements into a scope or the body of another construct.
fn label($word: String): String { "label=" + $word }
echo (label notebook)
let $literal = "notebook"
echo $literal
label=notebook
notebook
The word notebook is an argument in the first call. In let $x = notebook, it
would instead be a command to execute. Double or single quotes make text explicit.
Functions and calls describes each call context.
# starts a comment outside a string. A backslash followed by a newline joins
source lines:
let $title = "Northern " \
+ "lights"
echo $title # This comment is not part of the String.
Northern lights
A header line #tab-size N is a tokenizer directive rather than an ordinary
comment. It chooses tab stops for that source, with N from 1 through 32.
Original tabs and string contents are preserved. This matters when drawing
pipeline splits: \- starts a branch, and vertical | guides
must continue its connection across intervening diagram rows.
Use spaces around arithmetic operators. This avoids confusing a path such as
$root/file with division such as $root / $size.
Expressions produce values. Parentheses group one expression or request a nested
call; they do not contain a semicolon-separated mini-program. Functions, if, and
match can produce values from blocks. A standalone block is a statement scope.
() is the unit/no-value literal. It is useful for omitted values, optional types,
and iterator termination. It is not an empty function argument list:
do_work () passes one unit argument; do_work supplies no arguments.
Variables use $name or ${name}. Type names are case-sensitive: Integer and
integer are different names. any is the lowercase universal type constraint.
Module qualification uses ::, as in tools::run and $tools::setting.
Common punctuation has a dedicated page in the syntax reference.
The language's call rules apply to keywords used as arguments too: echo let
prints the word let.
Related: Variables and scope · Strings and paths
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use