I can't remember why, but a long time ago, I found that for some reason, I needed to set both of these variables. It caused no problems in bash, but now in zsh, when I put

export PATH=~/bin:/opt/local/bin:/opt/local/sbin:$PATH
export path=$PATH

(the same thing I used in .bashrc) in my initialization, I get

/Users/…/.zshenv:export:7: path: inconsistent type for assignment

What do they mean by "type," and what is $path used for?


The error mentioning ‘type’ refers to the data type of the variable, such as string or array.

$PATH is a string, $path is an array. You cannot assign a string, whether by variable or by literal, to a variable typed to contain an array, since the types do not match.

As for what the difference between the two variables are: they are meant to represent the same list of folders, but in different formats. $PATH containing /path/to/one:/path/to/two would mean that $path’s first element is /path/to/one and the second one is /path/to/two.

You shouldn’t need to manage the two variables (and assigning one to the other won’t work since the types do not match) — the shell should handle it for you. Simply append to the $PATH string and the path you add should exist as an element of $path.

This only applies in zsh, inherited from *csh. You can see the ‘binding’ between the two variables with typeset -p PATH.

$path being an array is really convenient:

  • appending and altering the path can be done with array operations like append rather than string manipulation (requiring splitting and joining in the case of editing somewhere in the middle).

  • looping through is just for i ($path) { … } without needing to deal with the setting of the right split character.

  • So, apparently bash automatically converts the types and doesn’t automatically assign both. I had to put the separate assignment to get something to work long ago. Don’t remember what. – WGroleau Sep 5 '20 at 21:49
  • So, why do we need both? – WGroleau Sep 5 '20 at 21:51
  • @WGroleau Updated answer – grg Sep 5 '20 at 22:11
  • 3
    @WGroleau In bash, $path doesn't have any special meaning (and generally doesn't exist). I have no idea why you'd need to set it. – Gordon Davisson Sep 6 '20 at 4:44
  • Well, I can't remember either. All I remember is that doing so fixed a problem. But that was at lest a decade ago. Come to think of it, it might have been in csh. – WGroleau Sep 6 '20 at 5:04

PATH is a scalar value- a continuous string of search paths separated by colons and path is an array of search paths. zsh will sync both path and PATH. There is no need for you to do so.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .