Why is there a number in the zsh parameter expansion ${1-$PWD}

That's not brace expansion, that's a standard parameter expansion operator (dates back to the Bourne shell in the 70s).

${1-$PWD}

Expands to the value of $1 (the first positional parameter) if it is set (if $# is strictly greater than 0) even to the empty string, or to the content of the $PWD variable otherwise.

Run:

info zsh 'Parameter Expansion'

for details.

typeset is not Bourne nor POSIX, but it's not zsh-specific either. It comes from the Korn shell (from the early 80s) and is used to limit the scope of a variable to the current function. It's also found in bash and yash.

Run:

info zsh typeset

for details.


${1-$PWD} is a shell parameter expansion pattern.

It is used to expand to a default value based on another -- whatever on the right of -. Here, in your case:

  • If $1 is unset, then the expansion of $PWD would be substituted

  • Otherwise i.e. if $1 is set to any value (including null), its value would be used as the result of expansion

Example:

% echo "Foo${1-$PWD}"   
Foo/home/bar

% set -- Spam

% echo "Foo${1-$PWD}"
FooSpam

It tests $1 for a value, using that before $PWD.