I try to set the $PATH reference to the current working directory, one machine work as expected, but another machine is not.

basically, I have set below line in .bashrc

export PATH=$PWD/bin:$PATH

if I move directory to /123, I expected that the $PATH will updated to /123/bin:$PATH but it isn't.

Are there anyway to make it read the current $PWD to use in $PATH?


Add the following line in ~/.bashrc to add ./bin directory in PATH

export PATH=./bin:$PATH

Next you need to run in terminal source ~/.bashrc to affect the change.

  • . should be ./bin if you reread their question. – Thomas Ward Dec 13 '13 at 19:23
  • @ThomasW. Thanks for correcting me, I am editing it. But at his first line he mentioned about current directory only. And never asked for ./bin/ in every directory. – sourav c. Dec 13 '13 at 19:25

If you want to be in the subdirectory bin of the current directory that is ./bin so:

export PATH=./bin:$PATH

The PATH variable is not automatically updated. When you move a folder such as /home/$USER/bin to /home/$USER/notbin you'll have to manually update your $PATH environment variable. That will fix the issue.

It may also help to manually update the full directory path you're adding to $PATH. If your directory you're adding to $PATH is /home/$USER/stuff/programs/someprogram/bin then $PWD won't really help you that much. Therefore, knowing where your stuff is stored, and putting in the full path, will make almost-certain that the correct directory ends up in the $PATH variable. (since .bashrc is located in your ~ dir, $PWD inside of ~/.bashrc will always be your home directory, when its called.)

  • Nice exhaustive explanation, +1 from me. – sourav c. Dec 13 '13 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.