Zsh variables, called parameters in the zshparam manual, give names to values a command line or script needs to reuse. They keep labels, counts, paths, and temporary environment settings in one place instead of repeating the same literal through several commands.
A scalar parameter is assigned with name=value and expanded with $name or ${name}. The typeset builtin declares parameters explicitly and can add attributes such as integer handling, while export marks selected scalar values for child process environments.
Values set in one shell stay in that shell unless they are exported. Use braces when a suffix touches the parameter name, quote expansions that must stay one argument, and use unset when a temporary parameter should no longer affect later commands.
Related: How to use arrays in Zsh
Related: How to manage PATH with the Zsh path array
Related: Use variables in Bash scripts
#!/usr/bin/env zsh
emulate -L zsh
setopt err_exit
typeset job="nightly backup"
typeset -i tries=3
log="${job}-${tries}.log"
export MODE=staging
print -r -- "job=$job"
print -r -- "tries=$tries"
print -r -- "log=$log"
zsh -fc 'print -r -- "child=$MODE"'
unset MODE
print -r -- "after=${MODE-unset}"
emulate -L zsh resets option behavior to native Zsh for this script scope. The -i attribute stores tries as an integer, and export copies MODE into child process environments.
$ zsh -n vars-demo.zsh
No output means Zsh parsed the assignments, expansions, and unset command without finding a syntax error.
$ zsh vars-demo.zsh job=nightly backup tries=3 log=nightly backup-3.log child=staging after=unset
The child shell sees MODE because it was exported. The final line shows that unset MODE removed the parameter from the parent script before the last expansion.
$ prefix=nightly
$ print -r -- "${prefix}_report"
nightly_report
Without braces, $prefix_report would ask for a different parameter named prefix_report instead of appending _report to $prefix.
print -r -- "job=$job"
Native Zsh does not split scalar parameters on spaces by default, but compatibility options such as sh_word_split can change that behavior. Quoted expansions keep the script's argument boundary explicit.
$ rm -f vars-demo.zsh