Adding any current directory './' to the search path in Linux

Brian Mckinlay picture Brian Mckinlay · Nov 28, 2014 · Viewed 65.6k times · Source

How do you add any current directory './' to the search path for executables in Linux?

Answer

Justin Doyle picture Justin Doyle · Jan 8, 2016

I know this is an old answer, but if anyone else stumbles across this question via Google like I did, here's a more detailed explanation.

If you want to make it so that search path contains the value of pwd at the time you set the search path, do:

export PATH=$PATH:$(pwd)

So, if pwd is /home/me/tmp, PATH will be set to $PATH:/home/me/tmp

However, If you want it so that whatever your present working directory is at the time you execute a command (ex; the value of pwd at any given time is in the search path), do:

export PATH=$PATH:.

So, if pwd is /home/me/tmp, PATH will be set to $PATH:.. If your present working directory contains a script called foo, then it would be fount in your PATH. If you change directories to one that does not contain foo, "foo" will not be found in the PATH any more.

You should note that having your present working directory in your PATH is a potential security risk, however.