What is setenv linux

What is setenv linux

NAME

setenv - change or add an environment variable

SYNOPSIS

#include stdlib.h> int setenv(const char *name, const char *value, int overwrite); int unsetenv(const char *name); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): setenv(), unsetenv(): _POSIX_C_SOURCE >= 200112L || /* Glibc versions 

DESCRIPTION

The setenv() function adds the variable name to the environment with the value value, if name does not already exist. If name does exist in the environment, then its value is changed to value if overwrite is nonzero; if overwrite is zero, then the value of name is not changed (and setenv() returns a success status). This function makes copies of the strings pointed to by name and value (by contrast with putenv(3)). The unsetenv() function deletes the variable name from the environment. If name does not exist in the environment, then the function succeeds, and the environment is unchanged.

RETURN VALUE

The setenv() function returns zero on success, or -1 on error, with errno set to indicate the cause of the error. The unsetenv() function returns zero on success, or -1 on error, with errno set to indicate the cause of the error.

ERRORS

EINVAL name is NULL, points to a string of length 0, or contains an '=' character. ENOMEM Insufficient memory to add a new variable to the environment.

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7). ┌─────────────────────┬───────────────┬─────────────────────┐ │InterfaceAttributeValue │ ├─────────────────────┼───────────────┼─────────────────────┤ │setenv(), unsetenv() │ Thread safety │ MT-Unsafe const:env │ └─────────────────────┴───────────────┴─────────────────────┘

CONFORMING TO

POSIX.1-2001, POSIX.1-2008, 4.3BSD.

NOTES

POSIX.1 does not require setenv() or unsetenv() to be reentrant. Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more recent glibc versions follow the POSIX.1-compliant prototype shown in the SYNOPSIS.

BUGS

POSIX.1 specifies that if name contains an '=' character, then setenv() should fail with the error EINVAL; however, versions of glibc before 2.3.4 allowed an '=' sign in name.

SEE ALSO

clearenv(3), getenv(3), putenv(3), environ(7)

COLOPHON

This page is part of release 5.05 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.

© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.

Источник

What is setenv linux

NAME

setenv - change or add an environment variable

SYNOPSIS

#include stdlib.h> int setenv(const char *name, const char *value, int overwrite); int unsetenv(const char *name); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): setenv(), unsetenv(): _BSD_SOURCE || _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600

DESCRIPTION

The setenv() function adds the variable name to the environment with the value value, if name does not already exist. If name does exist in the environment, then its value is changed to value if overwrite is nonzero; if overwrite is zero, then the value of name is not changed (and setenv() returns a success status). This function makes copies of the strings pointed to by name and value (by contrast with putenv(3)). The unsetenv() function deletes the variable name from the environment. If name does not exist in the environment, then the function succeeds, and the environment is unchanged.

RETURN VALUE

The setenv() function returns zero on success, or -1 on error, with errno set to indicate the cause of the error. The unsetenv() function returns zero on success, or -1 on error, with errno set to indicate the cause of the error.

ERRORS

EINVAL name is NULL, points to a string of length 0, or contains an '=' character. ENOMEM Insufficient memory to add a new variable to the environment.

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7). ┌─────────────────────┬───────────────┬─────────────────────┐ │InterfaceAttributeValue │ ├─────────────────────┼───────────────┼─────────────────────┤ │setenv(), unsetenv() │ Thread safety │ MT-Unsafe const:env │ └─────────────────────┴───────────────┴─────────────────────┘

CONFORMING TO

POSIX.1-2001, POSIX.1-2008, 4.3BSD.

NOTES

POSIX.1 does not require setenv() or unsetenv() to be reentrant. Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more recent glibc versions follow the POSIX.1-compliant prototype shown in the SYNOPSIS.

BUGS

POSIX.1 specifies that if name contains an '=' character, then setenv() should fail with the error EINVAL; however, versions of glibc before 2.3.4 allowed an '=' sign in name.

SEE ALSO

clearenv(3), getenv(3), putenv(3), environ(7)

COLOPHON

© 2019 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.

Источник

DESCRIPTION

The setenv() function adds the variable name to the environment with the value value, if name does not already exist. If name does exist in the environment, then its value is changed to value if overwrite is nonzero; if overwrite is zero, then the value of name is not changed (and setenv() returns a success status). This function makes copies of the strings pointed to by name and value (by contrast with putenv(3)).

The unsetenv() function deletes the variable name from the environment. If name does not exist in the environment, then the function succeeds, and the environment is unchanged.

RETURN VALUE

setenv() and unsetenv() functions return zero on success, or -1 on error, with errno set to indicate the error.

ERRORS

EINVAL name is NULL, points to a string of length 0, or contains an '=' character. ENOMEM Insufficient memory to add a new variable to the environment.

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7).

Interface Attribute Value
setenv (), unsetenv () Thread safety MT-Unsafe const:env

STANDARDS

HISTORY

Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more recent glibc versions follow the POSIX.1-compliant prototype shown in the SYNOPSIS.

CAVEATS

POSIX.1 does not require setenv() or unsetenv() to be reentrant.

BUGS

POSIX.1 specifies that if name contains an '=' character, then setenv() should fail with the error EINVAL; however, versions of glibc before glibc 2.3.4 allowed an '=' sign in name.

SEE ALSO

Package name: core/man-pages Version: 6.04-1 Upstream: https://www.kernel.org/doc/man-pages/ Licenses: GPL, custom Manuals: /listing/core/man-pages/ Table of contents

Powered by archmanweb, using mandoc for the conversion of manual pages.

The website is available under the terms of the GPL-3.0 license, except for the contents of the manual pages, which have their own license specified in the corresponding Arch Linux package.

Источник

Linux setenv command

Computer Hope

On Unix-like operating systems running the C shell, the setenv built-in command adds, or changes, the value of an environment variable.

Syntax

setenv VAR [VALUE]

Arguments

VAR The name of the variable to be set.
VALUE The value of the variable, as either a single word or a quoted string.

Description

setenv is a built-in function of the C shell (csh). It is used to define the value of environment variables.

If setenv is given no arguments, it displays all environment variables and their values. If only VAR is specified, it sets an environment variable of that name to an empty (null) value. If both VAR and VALUE are specified, it sets the variable named VAR to the value VALUE. setenv is similar to the set command, that also sets an environment variable's value. However, unlike set, setenv also "exports" this environment variable to any subshells. In this way, it is the equivalent of the bash command export.

For instance, if you are inside the c shell, and you use setenv to set the following variable:

We can then use the echo command to view the value of that variable:

Our value, "myvalue", was returned. Now let's run bash as a subshell:

and see if it knows the value of our variable MYVAR:

As you can see, the value of MYVAR was passed on to bash.

Now, let's see how set is different. Let's go back to csh by exiting the bash subshell:

. and use set to set another environment variable, MYVAR2:

(The syntax of set, as you can see, is slightly different. It uses an equals sign to assign a value.) Now let's check the value of MYVAR2:

And now let's go back to bash:

. and check the value of MYVAR2:

This time, no value is reported, because the variable was not "exported" to the subshell. So, when you are using csh, if you want environment variables to remain local to only the current shell, use set. If you want them to carry over to subshells as well, use setenv.

Examples

setenv PATH "/bin:/usr/bin:/usr/sbin:/usr/local/bin"

Sets the environment variable PATH. PATH is a list of path names separated by colons (":"), which are the default paths to search for executable files when a command is called. After you set PATH to the above value, the shell looks in the paths /bin, /usr/bin, /usr/sbin, and /usr/local/bin, in that order, for the executable files of any subsequent commands you run.

csh — The C shell command interpreter.
ksh — The Korn shell command interpreter.
set — Set the value of shell options and positional parameters.
sh — The Bourne shell command interpreter.

Источник

Читайте также:  Create two directories linux
Оцените статью
Adblock
detector