MERIDIAN DATA SYSTEMS // SCRIPTING

variables

DOCUMENT TYPE: SYSTEM REFERENCE NODE: variables 68 DOCUMENTS
MDS://KNOWLEDGE/SCRIPTING/variables
VARIABLES
=========

Variables store text that a script can reuse. A name starts with a letter or
underscore and can contain letters, numbers, and underscores.

ASSIGN A VALUE
--------------
Use NAME=value. Quote a value that contains spaces:

    LABEL="shift notes"
    REPORT="$HOME/notes.txt"

An empty assignment clears a custom variable:

    LABEL=

READ A VALUE
------------
Use $NAME or ${NAME} to expand a variable. Braces make the end of the name
clear when more characters follow:

    echo "$LABEL for $USER"
    echo "${LABEL}_archive"

Double quotes keep an expanded value together, including spaces. Single quotes
keep dollar signs literal in command arguments:

    echo '$LABEL'

An unset name expands to an empty value. Use env NAME to inspect a value and
unset NAME to remove a custom variable.

BUILT-IN VARIABLES
------------------
USER, HOSTNAME, HOME, PWD, and IP are provided by the virtual shell and cannot
be assigned or removed. These built-in variables are read-only. They describe
the current user, computer, home directory, working directory, and active
virtual IP address.

SCOPE AND LIMITS
----------------
Scripts start with the current shell's values. Assignments made by a script
last only for that run; the caller's variables and working directory are
restored when it finishes. Files created or changed by script commands remain.

The virtual shell supports plain text values and simple variable expansion,
not every Bash feature. It does not evaluate command substitutions or
arithmetic expressions. A script can use up to 64 custom variables, with
values up to 1024 characters each.