Marvin Noll
Marvin Noll

Reputation: 665

Multiple .bashrc profiles

Is there a way to switch between multiple .bashrc files and reload bash? I want to have two different sets of environment variables and switch between them. Preferably in a terminal emulator and/or with a keystroke.

Upvotes: 6

Views: 8362

Answers (3)

Gianluca
Gianluca

Reputation: 1

If you want you can have a look to a tool I wrote in pure-bash to manage multiple profiles. It will give you a function named switch_profile that will load function/aliases/export from multiple files. It also supports unloading the settings you have into a profile before loading another one so you can be sure that a particular setting (e.g. an export of a variable that may affect other programs behavior) will be cleared between switches. You can find it here I hope it will be useful.

Upvotes: 0

Enlico
Enlico

Reputation: 28366

If you want to switch from one bashrc to another while you are in one terminal, you can follow Eby Jacob's answer, but be aware that, as commented by @chepner, that this will not undo what the "main" ~/.bashrc has done.

If you want to switch select one of several .bashrcs before opening a terminal, then maybe you can have the ~/.bashrc file be a symbolic link to one of .bashrc1, .bashrc2, ..., and when you want to change, you simply reassign the link by ln -sf .myWinterBashrc ~/.bashrc.

Upvotes: 1

Eby Jacob
Eby Jacob

Reputation: 1458

Create different .bashrc files or any files which has your environment variables or even other data which you want in them, for example you can have three .bashrc files at your home directory.

  1. /home/user/.bashrc1. -- this file has one version of your env variables.
  2. /home/user/.bashrc2. -- this file has another version of your environment variables.
  3. /home/user/.bashrc. -- this file has the main environment variables which will be automatically called when bash shell is started up.

edit this file /home/user/.bashrc and make entries as below

alias env1='/home/user/.bashrc1'

alias env2='/home/user/.bashrc2'

Now execute command . $HOME/.bashrc

When you want env1 variables to be available in shell type env1 and to switch to env2 variables to be available in shell type env2

This is one way you could switch between two different environment variables

Upvotes: 3

Related Questions