How to remove multiple variables?

0115

To remove multiple environment variables in Linux, you can use the unset command followed by the names of the variables you want to remove. Here’s how to do it:

  1. Open your terminal.

  2. Use the unset command: You can remove multiple variables in a single command by listing them after unset. For example:

    unset VARIABLE1 VARIABLE2 VARIABLE3
    

    Replace VARIABLE1, VARIABLE2, and VARIABLE3 with the names of the variables you want to remove. For example:

    unset MY_VAR1 MY_VAR2 MY_VAR3
    
  3. Verify the Variables are Removed: You can check if the variables have been removed by using:

    echo $MY_VAR1
    echo $MY_VAR2
    echo $MY_VAR3
    

    If the variables have been successfully removed, these commands will not output anything.

Note:

  • Similar to removing a single variable, using unset will only affect the current shell session. To permanently remove variables, you need to delete or comment out their definitions in the shell configuration file (like ~/.bashrc or ~/.zshrc) and then source the file or restart the terminal.

0 Comments

no data
Be the first to share your comment!