I like to make command-line bash variables for testing or for other purposes. I give them generic names like a, b, var1... Sometimes I may forget which variables I've already used. Anyway, is there a single command to clear all bash variables? Now after running such a command, I want all bash variables that were defined by the user to become undefined. When echo $undefinedvariable is run, the result is a blank line. All built-in variables like $USER or $SHELL should remain untouched by this command.

  • just type: exec bash Commented Jan 4, 2017 at 6:47

1 Answer 1


Use the bellow command

 $ exec bash

It will clear all bash variable

  • 2
    But not exported ones.
    – Kusalananda
    Commented Jan 4, 2017 at 7:55

Not the answer you're looking for? Browse other questions tagged .