Home

unsetenv

unsetenv is a function provided by the C standard library on POSIX-compliant systems that removes an environment variable from the calling process’s environment. By modifying the process-wide environment, it affects the set of variables visible to code running in the same process and to subsequently executed programs.

The typical prototype is int unsetenv(const char *name); and it is usually declared in a standard header

Return value and error handling: On success, unsetenv returns 0. If an error occurs, it returns -1

Relationship to setenv: unsetenv is the counterpart to setenv. While setenv creates or updates an environment

Shell usage: In many Unix shells, unsetenv is not a built-in; shells such as bash and sh

See also: getenv, setenv, environ, execve.

such
as
stdlib.h.
The
function
removes
the
environment
variable
named
by
name
from
the
process’s
environment,
which
is
managed
as
a
global
environment
array
(often
accessible
as
environ).
and
sets
errno.
A
common
error
condition
is
an
invalid
argument,
such
as
a
NULL
pointer,
an
empty
name,
or
a
name
containing
an
'='
character,
in
which
case
errno
is
set
to
EINVAL.
If
the
named
variable
does
not
exist,
many
implementations
treat
the
call
as
a
no-op
and
still
return
0.
variable,
unsetenv
removes
it
from
the
environment.
After
calling
unsetenv,
subsequent
getenv
or
access
to
that
variable
will
reflect
its
absence,
and
it
will
not
be
inherited
by
child
processes
created
via
fork/exec.
use
a
different
command
(unset)
to
remove
shell
variables
or
exported
environment
variables.
Some
shells
in
the
C
shell
family
provide
a
built-in
named
unsetenv
that
operates
within
the
shell
environment.