Parameter expansion keeps small string changes inside a Zsh script when the script already has the value in a parameter. It fits default arguments, service labels, short prefixes, and path-derived filenames that should be built before the next command runs.
The common form is ${name...}, where braces separate the parameter name from the operation applied to its value. In ${empty:-fallback}, the colon makes Zsh use the fallback when the parameter is unset or empty, while modifiers such as :h, :t, :r, and :e work on path-like strings.
The sample script runs with a default service name and with an explicit service name. The output confirms which fields follow the argument, which fallback is used for an empty value, and how the (U) flag plus path modifiers build a rotated log filename.
Related: How to use variables in Zsh
Related: How to use arrays in Zsh
Related: How to use glob qualifiers in Zsh
Related: Use parameter expansion in Bash
$ mkdir -p /tmp/zsh-parameter-demo $ cd /tmp/zsh-parameter-demo
#!/usr/bin/env zsh
emulate -L zsh
setopt err_exit no_unset
service=${1:-api-worker}
empty=""
log_path="/srv/app/releases/${service}.log"
print -r -- "service=${service}"
print -r -- "fallback=${empty:-default-service}"
print -r -- "upper=${(U)service}"
print -r -- "prefix=${service:0:3}"
print -r -- "file=${log_path:t}"
print -r -- "dir=${log_path:h}"
print -r -- "rotated=${log_path:r}.1.${log_path:e}"
${1:-api-worker} supplies a default argument, (U) uppercases the value, and the path modifiers split /srv/app/releases/api-worker.log without basename or dirname.
$ zsh -n expansion-demo.zsh
No output means Zsh parsed the script without finding a syntax error.
$ zsh expansion-demo.zsh service=api-worker fallback=default-service upper=API-WORKER prefix=api file=api-worker.log dir=/srv/app/releases rotated=/srv/app/releases/api-worker.1.log
$ zsh expansion-demo.zsh frontend service=frontend fallback=default-service upper=FRONTEND prefix=fro file=frontend.log dir=/srv/app/releases rotated=/srv/app/releases/frontend.1.log
$ log_path="/srv/app/releases/monthly report.log"
$ print -r -- "${log_path:t}"
monthly report.log
Zsh does not split ordinary scalar parameter expansions on whitespace by default, but quotes still preserve empty values and protect scripts that later use arrays or option changes. Test dense forms with print -r -- before using them with commands such as rm, chmod, or mv.
$ cd /tmp $ rm -rf /tmp/zsh-parameter-demo