Reputation: 1623
I see in examples of .profile file in UNIX systems, that after giving a value to the PATH variable e.g. PATH=$PATH:.
and then it is exported export PATH
.
My question are 2:
PATH=$PATH:.
means that the current directory is added to PATH variable. But is this done only 1 time? I mean will it just add my home directory, or every time I change the directory it will add it to PATH?Upvotes: 2
Views: 178
Reputation: 98496
.profile
is sourced. But, just in case, it is exported anyway. If the variable weren't exported, it would still work in the current shell, but it wouldn't be inherited by any child process..
means the current directory, whatever it is, but it is never expanded to the real name of the directory (for that use pwd
enclosed in back-quotes). If you change the directory, the current directory will be in the path. That is similar to the behavior of other non UNIX-like operating systems (Windows and DOS), but it is generally considered a security risk. To minimize it, at least put it at the end of the PATH, as in your example.Upvotes: 3
Reputation: 70492
If you don't export PATH
, then when you start another program (or sub-shell), that program will not see the same value for $PATH
that you have. Exporting it means the value that you see is also seen by the child processes that your shell spawns.
Adding .
to the PATH
does not expand into your current directory name when you added it. It stays a .
. So whatever current directory you happen to be in will be the directory that gets searched for executables when you try to run a program.
Upvotes: 4
Reputation: 109272
If you don't export a variable, it will remain local to the script that's running, i.e. .profile
in this case. That means that if you reference $PATH
anywhere else, it will be empty.
The variable is only set when the statement is executed, i.e. when .profile
is run. Usually, this will only happen once (when you start the shell) and not when you change directories.
Upvotes: 0