Add to $PATH without resetting

I am trying to use a script to add a folder with automation scripts to the replit path variable. Once the script ends the path variable is unchanged. I’ve read this is because it isn’t updated in bashrc.

I can’t edit bashrc. on replit. How can I update the global path variable on replit and make it stick by using a script?

code snippet

Welcome to Ask! I’m not sure this is possible. I was able to edit .bashrc using nano, but the changes I made were not reflected so :man_shrugging: .

1 Like

So, I do know a bit about what you’re talking about. By using a script to install scripts to the $PATH, you are doing the right thing for now, but it will not save once the Repl is reset. Instead, try this:

  1. Make it install to a directory that is saved (/home/runner/whatevertheprojectis)
  2. Try editing the PATH variable using [env] in .replit, sorta like this (i am not great with editing the .replit file, look it up in the docs)
[env]
PATH = "$PATH:~/projectname/myfolder/bin"

It should be able to access it now. If the files need to load libraries, set $LD_LIBRARY_PATH too.

It’s the only idea I have, sorry if it doesn’t work.

1 Like

You can edit it in SECRETS and that works for me.
In bash I echo $PATH:$PWD/folder
Copy this and then make a new secret named PATH and paste this echo there. Reload the shell and your $PATH will be updated and remain when you close and reopen the repl.

~/shell$ echo $PATH:$PWD/folder

2 Likes

Apologies for the necropost but I found that the Repl Shell can load .bashrc by running

source .bashrc

but for some reason isn’t configured/configurable to load .bashrc automatically on Shell startup. Hoping this functionality can be implemented in some way.

Edit: Working Solution

Asked on Reddit and found that while .bashrc doesn’t work, moving the file to .config/bashrc does work instead. Hope that helps any future lone coder venturing into these depths.

mv .bashrc .config/bashrc