There are few different formats I have seen so far:

  1. With quotes and brackets:

  2. With quotes only:

  3. None:


Export all the same:

export PATH

Which is the correct/preferred way?


2 Answers 2


This is about shell variables in general, not just PATH.

Here are some examples of why "" and {} can reduce errors.

Putting it in quotes is safer: if you do a=hello world then you will not get what you expect, but for a="hello world" you will.

Using {} is also safer: doing h="hello"; echo "$hword" will not work, but h="hello"; echo "${h}word" will.


They all are effective. One isn't drastically better than the other, but I prefer:

export PATH=$PATH:/usr/local/bin

It takes care of the export and the setting of the path in one line. I also tend to not put the new path before the existing $PATH, but there are cases when that might be necessary to load newer self-compiled libraries before older system ones.

If you are trying to export variables then yes, you want to quote them, for instance:

export myservers="server1 server2 server3"

Now when you echo $myservers you will see:

[user]# echo $myservers
server1 server2 server3

But since this question relates to $PATH and not shell variables, then my original post still stands since there will never be a time where you are printing 'hello world' into your system path.

[user]# echo $PATH  ## Something you shouldn't be doing
/usr/local/bin:HELLO WORLD/sbin:/bin:/usr/sbin:WHY AM I DOING THIS?/usr/bin:/root/bin
  • Don't forget to quote your variables.
    – muru
    Feb 7, 2015 at 20:14
  • Note this example will produce a different result that the examples in the question: The order does matter. Feb 7, 2015 at 22:47
  • @richard Note, I do mention that in my paragraph.
    – devnull
    Feb 7, 2015 at 23:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.