How to unexport an exported variable in Bash on Linux?

How to unimport an imported variable in Bash on Linux? For example, first, I export a variable MODE like

export MODE=debug

but I want to unexport the MODE (not turn to be “”, should be truly non-defined).

You can

unset MODE

For your reference:

   unset [-fv] [-n] [name ...]
          For each name, remove the  corresponding  variable  or
          function.  If the -v option is given, each name refers
          to a shell variable, and  that  variable  is  removed.
          Read-only variables may not be unset.  If -f is speci‐
          fied, each name refers to a shell  function,  and  the
          function  definition  is removed.  If the -n option is
          supplied, and name is  a  variable  with  the  nameref
          attribute, name will be unset rather than the variable
          it references.  -n has no effect if the -f  option  is
          supplied.   If  no  options  are  supplied,  each name
          refers to a variable; if there is no variable by  that
          name,  any  function  with  that  name is unset.  Each
          unset variable or function is removed from  the  envi‐
          ronment  passed  to  subsequent  commands.   If any of
          FUNCNAME,  GROUPS,  or  DIRSTACK  are unset, they lose
          their special properties,  even  if  they  are  subse‐
          quently  reset.  The exit status is true unless a name
          is readonly.
Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *