14 added 66 characters in body
source | link

An environment variable is a shell variable which has been exported. This means that it will be visible as ana variable, not only in the shell session that created it, but also for any process (not just shells) that are started from that session.

VAR="hello"  # shell variable created
export VAR   # variable now part of the environment

Once a shell variable has been exported, it stays exported until it is unset, so there's usually no need to re-export it, or until its "export property" is removed (with export -n in bash), so there's usually no need to re-export it. Unsetting a variable with unset deletes it (no matter if it's an environment variable or not).

In C, this is done withenvironment variables may be accessed using getenv(), setenv(), putenv() and unsetenv(). Variables created with these routines are inherited in the same way by any process that the C program starts.

An environment variable is a shell variable which has been exported. This means that it will be visible as an variable, not only in the shell session that created it, but also for any process (not just shells) that are started from that session.

VAR="hello"
export VAR

Once a shell variable has been exported, it stays exported until it is unset, so there's usually no need to re-export it, or until its "export property" is removed (with export -n in bash). Unsetting a variable with unset deletes it (no matter if it's an environment variable or not).

In C, this is done with getenv(), setenv(), putenv() and unsetenv(). Variables created with these routines are inherited in the same way by any process that the C program starts.

An environment variable is a shell variable which has been exported. This means that it will be visible as a variable, not only in the shell session that created it, but also for any process (not just shells) that are started from that session.

VAR="hello"  # shell variable created
export VAR   # variable now part of the environment

Once a shell variable has been exported, it stays exported until it is unset, or until its "export property" is removed (with export -n in bash), so there's usually no need to re-export it. Unsetting a variable with unset deletes it (no matter if it's an environment variable or not).

In C, environment variables may be accessed using getenv(), setenv(), putenv() and unsetenv(). Variables created with these routines are inherited in the same way by any process that the C program starts.

13 added 182 characters in body
source | link
$ var="hello"   # create shell variable "var"
$ bash          # start _new_ bash session
$ echo $var  "$var"   # no output
$ exit          # back to original shell session
$ echo $var  "$var"   # "hello" is outputted
$ unset var     # remove variable

$ export VAR="hello"  # create environment variable "VAR"
$ bash
$ echo $VAR  "$VAR"         # "hello" is outputted since it's exported
$ exit                # back to original shell session
$ unset VAR           # remove variable

$ ( export VAR="hello"; echo "$VAR" )  # set env. var "VAR" to "hello" in subshell and echo it
$ echo "$VAR"         # no output since a subshell has its own environment
$ var="hello"   # create shell variable "var"
$ bash          # start _new_ bash session
$ echo $var     # no output
$ exit          # back to original shell session
$ echo $var     # "hello" is outputted
$ unset var     # remove variable

$ export VAR="hello"  # create environment variable "VAR"
$ bash
$ echo $VAR           # "hello" is outputted since it's exported
$ exit                # back to original shell session
$ unset VAR           # remove variable
$ var="hello"   # create shell variable "var"
$ bash          # start _new_ bash session
$ echo "$var"   # no output
$ exit          # back to original shell session
$ echo "$var"   # "hello" is outputted
$ unset var     # remove variable

$ export VAR="hello"  # create environment variable "VAR"
$ bash
$ echo "$VAR"         # "hello" is outputted since it's exported
$ exit                # back to original shell session
$ unset VAR           # remove variable

$ ( export VAR="hello"; echo "$VAR" )  # set env. var "VAR" to "hello" in subshell and echo it
$ echo "$VAR"         # no output since a subshell has its own environment
12 added 2 characters in body
source | link

Environment variables may be listed with env (without any arguments). Other than that, they appear the same as non-exported shell variables in a shell session. This is a bit special for the shell as most other programming languages don't usually intermix "ordinary" variables with environment variables This is a bit special for the shell as most other programming languages don't usually intermix "ordinary" variables with environment variables (see below).

There are library functions in most programming languages that allows for getting and setting the environment variables. Note that since environment variables are stored as a simple key-value relationship, they are not usually "variables" of the language. A program may fetch the value (which is always a character string) corresponding to a key (the name of the environment variable), but will then have to convert it to an integer or whatever data type the language expects the value to have.

Environment variables may be listed with env (without any arguments). Other than that, they appear the same as non-exported shell variables in a shell session. This is a bit special for the shell as most other programming languages don't usually intermix "ordinary" variables with environment variables (see below).

There are library functions in most programming languages that allows for getting and setting the environment variables.

Environment variables may be listed with env (without any arguments). Other than that, they appear the same as non-exported shell variables in a shell session. This is a bit special for the shell as most other programming languages don't usually intermix "ordinary" variables with environment variables (see below).

There are library functions in most programming languages that allows for getting and setting the environment variables. Note that since environment variables are stored as a simple key-value relationship, they are not usually "variables" of the language. A program may fetch the value (which is always a character string) corresponding to a key (the name of the environment variable), but will then have to convert it to an integer or whatever data type the language expects the value to have.

11 Spelling fixes
source | link
10 added 156 characters in body
source | link
9 deleted 15 characters in body
source | link
8 added 435 characters in body
source | link
7 added 189 characters in body
source | link
6 added 189 characters in body
source | link
5 added 152 characters in body
source | link
4 added 558 characters in body
source | link
3 added 558 characters in body
source | link
2 added 114 characters in body
source | link
1
source | link