Ask coding questions

← Back to all posts
How to add current working directory to the PATH environment variable
ashokb (5)

I am compiling multiple executables.
And I want to be able to execute it when I am in the current working directory.
How to add the CWD to the environment PATH variable?

I have .bashrc and within it I have:
export PATH=/home/runner/Unit5Programs:$PATH

But it gets reset every time I press the "Run" button. How to make this work?

Comments
hotnewtop
isbur (0)

Hi! I found a somewhat sneaky solution to this issue. It uses a comparatively recent Secrets feature. Yes, just put desired PATH contents to secret named "PATH", for example, you can echo default PATH contents and than copy it cocatenating with your own paths.

However, some system-wide settings affecting PATH value may be changed later, and as this solution is basically forcible rewriting of PATH variable you may need to manually update the "secret" according to changes that took place.