Skip to content

Strings and Paths

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

Strings and paths

Text and interpolation

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.

Indexing and methods

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 and display

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

Clone this wiki locally