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?
You just need to use the command unset
:
unset foo1
It doesn't matter if foo1
isn't an environment variable.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With