clear out all variables without closing terminal

clear out all variables without closing terminal

https://unix.stackexchange.com/questions/172655/clear-out-all-variables-without-closing-terminal

I want to know how to clear all variables which I defined in command prompt without closingterminal ?

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

---------------------------

If you do

exec bash

you will use a fresh & new environnement

--------------------------------------------------

https://stackoverflow.com/questions/15825353/bash-array-export

You can't export an array in Bash (or any other shell). Bash will never export an array to the environment (until maybe implemented someday, see the bugs section in the manpage).

There are a couple things going on here. Again, setting the -x attribute on an array is nonsensical because it won't actually be exported. The only reason you're seeing those results is because you defined the array before localizing it, causing it to drop down to the next-outermost scope in which that name has been made local (or the global scope).

So to be clear, whenever you use a declaration command, you're always creating a local except when you use export or readonly with a non-array assignment as an argument, because these are POSIX, which doesn't specify either locals or arrays.

原文地址:https://www.cnblogs.com/oxspirt/p/7646560.html