Repository navigation
Strings and Paths
Single and double quotes both process backslash escapes. Double quotes also
interpolate variables; single quotes keep $ references literal.
let $animal = "otter"
echo "river ${animal}"
echo '$animal stays text'
echo "λ猫".count "λ猫".chars...
river otter
$animal stays text
2 λ 猫
Use \n, \r, \t, and \$ for common escapes. Character escapes also
accept hexadecimal \x41, octal \o101, and decimal \065 (all produce A).
Braced interpolation can access member paths, including a dynamic member name.
It is not an arbitrary embedded expression language: bind an indexed or
computed value to a local before interpolating it. For example, use
let $first = $items[0] followed by "first: ${first}".
Multiline quotes use "* ... *" or '* ... *'. The first content line establishes
indentation to remove from later lines. Additional indentation and line breaks
remain part of the String.
let $word = "café猫"
echo $word[3] $word[4..]
echo ($word.replace "café" "tea")
echo ("notes.md".strip_suffix ".md")
é 猫
tea猫
notes
String indexes and slices operate on Unicode characters. Reading a slice creates
a String. Update text by assignment, concatenation, or methods such as replace.
Core methods are chars, contains, starts_with, ends_with, replace,
split, trim, trim_start, and trim_end. The prelude adds count, pad,
strip_prefix, and strip_suffix. Methods return values; trimming is explicit.
Paths are Strings. Variable reads and interpolation shorten complete leading
home-directory prefixes to ~. Stored values are not changed. Filesystem
operations and external command arguments expand a leading ~ or ~/ again;
embedded text such as "cwd: ${pwd}" keeps the shortened display.
~someone is not expanded. Quoting a path protects argument boundaries.
$root/file.txt is a single path word, even if $root contains spaces.
${name}suffix ends the variable name before the suffix. Use $a / $b for
arithmetic division.
Unquoted globs *, ?, bracket classes, and ** produce sorted file matches.
Use a path prefix for a bracket glob, such as ./[ab].txt; a leading [ is a
collection literal. Hidden names need an explicit dot prefix. An unmatched glob
is an error. Quote a pattern to pass it as text.
Use dir_exists and file_exists for native filesystem predicates. The path
prelude function displays PATH entries and marks directories that do not exist.
Related: Arrays · Environment · Redirection
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