To unset (remove) exported variables in a Linux shell, you can use the unset command, just like you would for local variables. Here’s how to do it:
Steps to Unset Exported Variables
-
Unset the Exported Variable: Use the
unsetcommand followed by the variable name to remove the exported variable.unset VARIABLE_NAMEExample:
export MY_VAR="Hello, World!" echo $MY_VAR # Outputs: Hello, World! unset MY_VAR -
Verify the Variable is Unset: After unsetting the variable, you can check if it has been successfully removed by using the
echocommand.echo $VARIABLE_NAMEIf the variable has been unset, this command will produce no output.
Example:
echo $MY_VAR # Outputs nothing, indicating the variable has been unset -
Check with the
envCommand: You can also use theenvcommand to confirm that the variable is no longer listed among the environment variables.env | grep VARIABLE_NAMEIf the variable has been unset, this command will yield no results.
Example:
env | grep MY_VAR # Outputs nothing, confirming that MY_VAR is not set
Summary
- Use
unset VARIABLE_NAMEto remove an exported variable. - Check with
echo $VARIABLE_NAMEto see if it outputs nothing. - Use
env | grep VARIABLE_NAMEto confirm it is not listed among environment variables.
If you have any further questions or need additional assistance, feel free to ask!
