How to undefine and unset a bash environment variable on Linux or Unix

You can undefine and unset a bash environment variable using the unset command in the terminal.

For example, if you have an environment variable named MY_VAR, you can undefine and unset it by running the following command:

unset MY_VAR

After running this command, the variable MY_VAR will no longer be defined, and any attempt to reference it will result in an error.

Note that the change will only affect the current shell session. If you want to permanently remove the variable, you’ll need to unset it in the appropriate configuration file for your shell. For example, if you’re using bash, you can remove the variable by editing the ~/.bashrc file and removing the line that sets the variable.

Leave a Comment