Skip to main content
added 21 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In short: You set the shell variable "here" but it will not be available "there" (in ./test).

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.

In short: You set the environment variable "there" (in ./test) but not "here".

If you have an existing variable FOO_VARIABLE that you want a script or program to inherit as a environment variable, you will have to export it, i.e. make an environment variable from it:

FOO_VARIABLE=foo
export FOO_VARIABLE
./test

or, shorter

export FOO_VARIABLE=foo
./test

This sets the variable locally as well as makes it available in any created process (in ./test for example).

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In short: You set the shell variable "here" but not "there" (in ./test).

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.

In short: You set the environment variable "there" (in ./test) but not "here".

If you have an existing variable FOO_VARIABLE that you want a script or program to inherit as a environment variable, you will have to export it, i.e. make an environment variable from it:

FOO_VARIABLE=foo
export FOO_VARIABLE
./test

or, shorter

export FOO_VARIABLE=foo
./test

This sets the variable locally as well as makes it available in any created process (in ./test for example).

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In short: You set the shell variable "here" but it will not be available "there" (in ./test).

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.

In short: You set the environment variable "there" (in ./test) but not "here".

If you have an existing variable FOO_VARIABLE that you want a script or program to inherit as a environment variable, you will have to export it, i.e. make an environment variable from it:

FOO_VARIABLE=foo
export FOO_VARIABLE
./test

or, shorter

export FOO_VARIABLE=foo
./test

This sets the variable locally as well as makes it available in any created process (in ./test for example).

added 134 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In short: You set the shell variable "here" but not "there" (in ./test).

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.

In short: You set the environment variable "there" (in ./test) but not "here".

If you have an existing variable FOO_VARIABLE that you want a script or program to inherit as a environment variable, you will have to export it, i.e. make an environment variable from it:

FOO_VARIABLE=foo
export FOO_VARIABLE
./test

or, shorter

export FOO_VARIABLE=foo
./test

This sets the variable locally as well as makes it available in any created process (in ./test for example).

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In short: You set the shell variable "here" but not "there" (in ./test).

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.

In short: You set the environment variable "there" (in ./test) but not "here".

If you have an existing variable FOO_VARIABLE that you want a script or program to inherit as a environment variable, you will have to export it, i.e. make an environment variable from it:

FOO_VARIABLE=foo
export FOO_VARIABLE
./test

or, shorter

export FOO_VARIABLE=foo
./test

This sets the variable locally as well as makes it available in any created process (in ./test for example).

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

In the first command,

FOO_VARIABLE=foo;./test

you assign the shell variable FOO_VARIABLE a value. Then you call ./test. Since FOO_VARIABLE is not exported, it is not an environment variable and it will therefore not be inherited by any script or program that you run. This is why ./test does not know about the variable.

In the other command,

FOO_VARIABLE=foo ./test

you set the value of FOO_VARIABLE in the environment of ./test (i.e. you create an environment variable fro ./test called FOO_VARIABLE). The variable is not set in the current environment as an environment variable nor as a shell variable, only for the process resulting from running ./test.