I want to know how to clear all variables which I defined in command prompt without closing terminal ?
for example, if I set a variable in command prompt as:
$ a=1
now I want to delete the variable $a (and many other variables defined in similar way) without closing terminal. I could use unset but it will be hectic if there are large no. of variables
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you do (GNU coreutils)
exec env --ignore-environment /bin/bash
you will use a fresh & new environment
Method 2
You could use env, which is provided by GNU coreutils (typically preinstalled on GNU/Linux systems):
exec env --ignore-environment /bin/bash
The exec system call is so that your current process is replaced in-place by the new, environment-less version of your shell.
This has the benefit to also clear any exported environment variables.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0