Repository navigation
Environment
A variable's shell visibility and a declaration's module visibility are different.
let export includes a binding in child-process environments. pub exports a
symbol to importing Shelly modules.
let $local_note = "draft"
let export $SHELLY_WIKI_NOTE = "published"
let $bindings = get_env
echo $bindings["local_note"].value
echo $bindings["SHELLY_WIKI_NOTE"].visibility
draft
VariableVisibility::Exported
get_env returns [String: VariableInfo] for the visible scope, including
shadowing. Keys and name omit the leading $. VariableInfo contains name, value, and a VariableVisibility
(Local or Exported). These are snapshots of the binding information.
optional_env reads an environment name and returns a String or ().
let type converts an existing binding and retains the conversion back to its
original environment representation. The prelude supplies colon-separated
String/array conversions, preserving empty entries.
let export $SHELLY_WIKI_PATH = "red::blue"
let type $SHELLY_WIKI_PATH = [String]
echo $SHELLY_WIKI_PATH.count
$SHELLY_WIKI_PATH = [$SHELLY_WIKI_PATH..., "green"]
/usr/bin/printenv SHELLY_WIKI_PATH
3
red::blue:green
This is useful for $PATH: work with [String] inside Shelly while children
receive the conventional colon-separated text. Conversion uses target
from_<source>, then source to_<target>, then built-in conversions.
| Variable | Purpose |
|---|---|
$args |
Script arguments. |
$shelly |
Current Shelly executable. |
$pid |
Current process ID. |
$pwd |
Current directory in user-facing path form. |
$os |
Platform name, such as linux or macos. |
$tty_color_mode |
Native TtyColorMode enum. |
$SHELLY_MODULE_PATH |
Search directories for ordinary imports. |
$SHELLY_STD_PATH |
Override standard-library search. |
$SHELLY_STD_FOUND |
Selected prelude root, embedded, or (). |
$SHELLY_TAB_SIZE |
Default source tab stops, from 1 through 32; defaults to 4. |
A source's #tab-size N directive takes precedence over an explicit --tab-width N
option, which takes precedence over $SHELLY_TAB_SIZE. Set the variable in a
startup script to affect later submissions and module loads. Export it when child
Shelly processes should inherit it. See pipeline splits.
Prompt, widget, history, and highlighting settings are described in their own chapters. Environment variable names are case sensitive.
Related: Variables · Conversions · Startup
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