I have portable terminal with bash shell on usb drive, and I want to load different environment variables every time I change computer, users are different on other machines. How to setup .bashrc file for this?
I am not certain I completely understand what you want to do.
I suspect that what you will basically want is to keep a few environment files you can source when/where needed.
Assuming you wanted to have your environment set on a remote machine you ssh into, then your .bashrc could contain something like
Do keep in mind that .bashrc may not be the file you do need to edit. From my system's bashrc:
# There are 3 different types of shells in bash: the login shell, normal shell # and interactive shell. Login shells read ~/.profile and interactive shells # read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all # settings made here will also take effect in a login shell.
If you are switching users locally, this approach would also work.
If what you wanted was to modify your own environment (not sure why you would, but not here to judge), then probably the easiest is to just manually source whatever env file you need as and when you need it.
It sort of sounds like you are on Windows, though, in which case you might need to make sure your local shell works similar to bash, and allows sourcing things.
Also, do keep in mind you can use the
env command to run things, as in:
env -i bash -c 'source .foo.env && do_something.sh'