What I noticed is that when I add a :$PATH
to the first PATH
, it repeats all the path when you echo
it.
I use the MANPATH
for example, but the same thing happens with the PATH
variable.
# I use MANPATH here
export MANPATH="/usr/local/share/man" # Here no :$MANPATH
export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
export MANPATH="/usr/local/opt/make/libexec/gnuman:$MANPATH"
This outputs:
$ echo $MANPATH
/usr/local/opt/make/libexec/gnuman:/usr/local/opt/coreutils/libexec/gnuman:/usr/local/share/man
But when I add :$MANPATH
to the first one:
export MANPATH="/usr/local/share/man:$MANPATH"
export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
export MANPATH="/usr/local/opt/make/libexec/gnuman:$MANPATH"
This outputs:
$ echo $MANPATH
/usr/local/opt/make/libexec/gnuman:/usr/local/opt/coreutils/libexec/gnuman:/usr/local/share/man:/usr/local/opt/make/libexec/gnuman:/usr/local/opt/coreutils/libexec/gnuman:/usr/local/share/man:
As you see, all the MANPATH are repeated.
So my questions are:
- Should I omit the
:$PATH
or$MANPATH
at the end of the first line? - Why it repeats all the paths when I add it to the end of the first line?
export
to make a shell variable an environment variable. Exporting it in every assignment is not needed. You don't need to export variables that already are environment variables, likePATH
(unless youunset
them). – Kusalananda Mar 14 '21 at 11:18