Search code examples
linuxbashvariablesundefined

undefine a variable in BASH


In order to save some time typing same phrase many times, I defined some variables in in BASH (not a bash file, just the command line bash). How careless I was to give a variable wrong name foo1 instead of foo. So, I want to undefine foo1.

I know I can set foo1 empty and define foo. By doing this, foo1 is still there and may confuse. I cannot use unset to undefine foo1 because it is not an environment variable.

Question: How to undefine a variable in BASH?


Solution

  • You just need to use the command unset:

    unset foo1
    

    It doesn't matter if foo1 isn't an environment variable.