Skip to content

Instantly share code, notes, and snippets.

@jeremy-code
Created April 4, 2025 23:53
Show Gist options
  • Save jeremy-code/4dad367eaa684e171dc81d4c7670d59a to your computer and use it in GitHub Desktop.
Save jeremy-code/4dad367eaa684e171dc81d4c7670d59a to your computer and use it in GitHub Desktop.
ZSH path setting

If you check out https://zsh.sourceforge.io/Guide/zshguide02.html#l24, a neat trick to set up your PATH variable is:

typeset -U path
path=(~/bin ~/progs/bin $path)

.

I was editing my .zprofile from

typeset -U path
path=(
  $path
)

to

typeset -U path
path=(
  "${path}"
)

when I suddenly got some really bizarre errors, such as

/etc/zshrc:7: command not found: locale

on startup and

prompt_status:9: file name too long: wc

every time I used a command, and a lot of built-in commands weren't working.

I figured out that the reason is that "${var}" !== $var if var is an array. The code you actually want if you want is:

typeset -U path
path=(
  "${HOME}/.local/bin"
  "${path[@]}"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment