That line in your .profile
should be one of
export PATH="$PATH:$HOME/Unix/homebrew/bin"
PATH="$PATH:$HOME/Unix/homebrew/bin"
PATH=$PATH:$HOME/Unix/homebrew/bin
PATH=$PATH:~/Unix/homebrew/bin
The ~
character is only expanded to your home directory when it's the first character of a word and it's unquoted. In what you wrote, the ~
is between double quotes and therefore not expanded. Even if you wrote export "PATH=$PATH:"~/Unix/homebrew/bin
, the ~
would not be expanded because it is not at the beginning of a shell word.
There is a special dispensation, which is intended to write values for PATH
and similar variables. If ~
is just after the equal sign that marks an assignment, or if ~
is just after a :
in the right-hand side of an assignment, then it's expanded. Only plain assignments have this dispensation, export PATH=…
does not count (it's a call to the export
builtin, which happens to have an argument that contains a =
character).
Here, you do not need to export PATH
because it's already exported. You don't need to call export
when you change the value of a variable (except in old Bourne shells that you won't find on OSX or Linux). Also, in an assignment (again, export
does not count), you do not need double quotes around the right-hand side, so PATH=$PATH:~/Unix/homebrew/bin
is safe even if $PATH
contains spaces.
which
is not at fault here; the~
should have been expanded in the definition ofPATH
. There's an oddity in bash that it expands the~
anyway inPATH
, so two wrongs make a right, kind of. – Gilles 'SO- stop being evil' Nov 29 '11 at 21:57~
is a bash oddity. Having that literal~
in$PATH
is likely to cause trouble down the line because there are programs that do their own splitting of$PATH
and they don't treat~
specially. – Gilles 'SO- stop being evil' Nov 29 '11 at 23:14~
”, your sentence is misleading. In the context of$PATH
, this is every program other than bash. – Gilles 'SO- stop being evil' Nov 30 '11 at 01:07type -p
may be superior,which
is far easier to remember for a command that you type once every few months. – icc97 Jul 30 '19 at 10:16