mshell has two variable namespaces: mshell variables (typed values stored in the interpreter)
and environment variables (strings stored in the process environment).
They use different sigils and behave differently.
Store a value with the ! suffix and retrieve it with @.
Storing pops the top of the stack; retrieval pushes the stored value back onto the stack.
42 answer!
@answer 1 + total!
@total wl
Retrieving an unknown variable results in an error.
Mshell variables do not consult the environment, so @name only looks in the mshell variable map.
Environment variables are accessed with $NAME.
They are always strings.
Use $NAME! to set them and $NAME? to check for existence.
Reading a missing environment variable with $NAME is an error.
Environment variables are always exported to subprocesses, so setting them affects subsequent command executions.
"info" $LOG_LEVEL!
$LOG_LEVEL wl
$EDITOR? if
$EDITOR wl
else
"vim" wl
end
You can print all environment variables (sorted by key) using the built-in .env function.
.env
"/tmp" $TMPDIR!
['my-tool']!
Changing directories updates PWD and OLDPWD in the environment.
You can read them the same way as any other environment variable.
$PWD wl
`/tmp` cd
$OLDPWD wl