Un-exporting an Exported Variable in Bash in Linux

How to un-export 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

export -n MODE

or

unset MODE

For your reference (from the [`bash` manual](https://www.systutorials.com/docs/linux/man/1-bash/)):

export [-fn] [name[=word]] ...
export -p
      The supplied names are marked for automatic export to the en‐
      vironment  of  subsequently executed commands.  If the -f op‐
      tion is given, the names refer to functions.  If no names are
      given,  or  if  the -p option is supplied, a list of names of
      all exported variables is printed.  The -n option causes  the
      export  property to be removed from each name.  If a variable
      name is followed by =word, the value of the variable  is  set
      to  word.   export  returns an exit status of 0 unless an in‐
      valid option is encountered, one of the names is not a  valid
      shell  variable  name,  or -f is supplied with a name that is
      not a function.
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
     COMP_WORDBREAKS,  RANDOM,  SECONDS,  LINENO,  HISTCMD,
     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.

Similar Posts

  • |

    git push error

    $ git push error: The requested URL returned error: 403 Forbidden while accessing https://github.com/HarryWei/hummer.git/info/refs fatal: HTTP request failed Replace (or add) url=ssh://git@github.com/HarryWei/hummer.git with url=https://git@github.com/HarryWei/hummer.git under “[remote “origin”]” section in ~/.gitconfig file. Reference:http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed Read more: Git push error under CENTOS 6.7 Push and Pull data from Restful Service in Asp.net MVC Application using Angular JS Fixing…

  • |

    Sorting Two Lists Together According to The Order of One List in Python

    We may use two lists to store the values of two properties of a list of elements in Python. Under such data structure arrangement, when we need to sort the properties from one list, we may want to also make sure the other list will be also re-ordered following the same order as the first…

  • how to remove specific directories recursively

    How to remove .svn directories under hlfs dir recursively as follows. weiwei@weiwei-HP-Compaq-dx6128-MT-PX478AV:~/workshop1/hlfs > find ./ -name “.svn” ./test/build/.svn ./test/.svn ./output/conf/.svn ./output/lib32/.svn ./patches/.svn ./src/include/.svn ./src/include/api/.svn ./src/snapshot/.svn ./src/snapshot/unittest/build/.svn ./src/snapshot/unittest/.svn ./src/utils/.svn ./src/clean/Mapreducer/build/.svn ./src/clean/Mapreducer/.svn ./src/clean/.svn ./src/clean/unittest/.svn ./src/icache/.svn ./src/icache/unittest/.svn ./src/backend/.svn ./src/storage/.svn ./src/cache/.svn ./src/cache/unittest/.svn ./src/clone/.svn ./src/tools/.svn ./src/tools/unittest/.svn ./src/logger/.svn weiwei@weiwei-HP-Compaq-dx6128-MT-PX478AV:~/workshop1/hlfs > find ./ -name “.svn” | xargs rm -rf Read more: Generating…

  • Proxy using SSH Tunnel on Windows

    This article is an instruction of how to use https://www.systutorials.com/proxy-using-ssh-tunnel/ on a Windows machine. The mechanism is similar as the one in https://www.systutorials.com/proxy-using-ssh-tunnel/ with “Proxy listening to localhost port only”. Download PuTTY PuTTY is the software we use here for port forwarding. Please download it following the links in https://www.systutorials.com/open-source-and-portable-ssh-scp-sftp-and-vnc-clients-for-windows-to-remote-control-linux/. Configure PuTTY and create a…

One Comment

  1. export -n MODE

    See
    help export
    export: export [-fn] [name[=value] …] or export -p
    Set export attribute for shell variables.

    Marks each NAME for automatic export to the environment of subsequently
    executed commands. If VALUE is supplied, assign VALUE before exporting.

    Options:
    -f refer to shell functions
    -n remove the export property from each NAME
    -p display a list of all exported variables and functions

    An argument of `–‘ disables further option processing.

    Exit Status:
    Returns success unless an invalid option is given or NAME is invalid.

Leave a Reply

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