Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 529
Peng Zhang Avatar asked Oct 21 '14 15:10

Peng Zhang


2 Answers

You just need to use the command unset:

unset foo1

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

like image 57
Knut Holm Avatar answered Sep 28 '22 08:09

Knut Holm


as @BroSlow comments, yes you will use unset:

$ foo1=something
$ foo="something else"
$ set | grep ^foo
foo='something else'
foo1=something
$ unset foo1
$ set | grep ^foo
foo='something else'
like image 24
glenn jackman Avatar answered Sep 28 '22 08:09

glenn jackman