Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - $PATH and ${PATH}

What is the difference between using an environment variable, like PATH, as $PATH or ${PATH}?

like image 751
mk12 Avatar asked Sep 12 '09 20:09

mk12


1 Answers

There's no difference in most cases. The only times it matters is if you want to include trailing text after the expansion. For example, suppose your PATH contained the string FOO (not actually a valid path, but this is for an example), and you wanted to form the string FOOBAR. If you did

$PATHBAR

You would get the expansion of the variable named PATHBAR, which is probably not what you wanted. If you did

$PATH BAR

You would get a space between FOO and BAR, also not what you wanted. The solution is to use braces:

${PATH}BAR

This gives you FOOBAR.

like image 131
Adam Rosenfield Avatar answered Sep 26 '22 18:09

Adam Rosenfield