Adding any current directory './' to the search path in Linux [closed] Adding any current directory './' to the search path in Linux [closed] linux linux

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


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.


If you want to permanently add the directory you're currently in to the PATH variable you can use

$ echo "export PATH=\$PATH:$(pwd)" >> ~/.bashrc

which will expand $(pwd) to the string literal of your current directory and append the quoted line to your bashrc. Note the \ in \$PATH is needed to escape the expansion of $PATH to its current value.

$ pwd/path/to/suuuuuuuuuuuuuuuuuuuuper/long/foo/directory/bin$ echo "export PATH=\$PATH:$(pwd)" >> ~/.bashrc$ tail ~/.bashrc -n 1export PATH=$PATH:/path/to/suuuuuuuuuuuuuuuuuuuuper/long/foo/directory/bin


Um...that didn't work for me. I would do

export PATH=$(pwd):$PATH

The command previously posted literally just adds the dot.