This is a simple Bash project that lets you update your environment by commenting and uncommenting environment variable definitions (e.g., export JAVA_HOME).
-
bashrc- A custom bashrc file that includes environment variable definitions and useful functions.
- Can be used for testing environment variable switching.
-
switch_variables.sh- Uncomments a line if exactly one match is found and comments out all other lines.
- Displays matching lines and prompts you to refine your search if multiple matches are found.
- Automatically updates your current shell environment by sourcing the modified
bashrc.
- Bash shell (version 4 or above is recommended)
- Standard Unix utilities:
grepandsed
To uncomment the line in bashrc containing export JAVA_HOME that matches 11 and comment out every other line with export JAVA_HOME, you can use:
source ./switch_variables.sh ./bashrc JAVA_HOME 11source switch-variables/bashrcAfter sourcing the provided bashrc, you will have access to two functions that serve as shortcuts for the current shell:
switch_variable JAVA_HOME 11Or the shortcut:
switch_java 11You can install this script by sourcing the custom bashrc in your actual ~/.bashrc:
source <your_path>/switch-variables/bashrcIf you want to use a different file to manage your environment variables (e.g., your actual ~/.bashrc), edit the BASHRC_FILE accordingly.
Contributions are welcome! If you find any errors in the scripts or documentation, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.