user3553913
user3553913

Reputation: 433

How to change the value of environment variable inside shell script

I have kubernetes pod environment variable

JOBID=111

I am changing this env variable from inside a shell script like below. This change is happening inside an infinite loop. so script never terminates.

export JOBID=$(echo $line)

Inside the script the value of variable is changed to new value. But if I check the value of the env varible outside the script, inisde a new terminal the value of the env variable is still 111.

Upvotes: 0

Views: 1239

Answers (1)

Matt
Matt

Reputation: 8152

Inside the script the value of variable is changed to new value. But if I check the value of the env varible outside the script, inisde a new terminal the value of the env variable is still 111

This is how environment variables work and you cannot change it. You can only change variable for a specific process, and this env will propagate for every other process you run from this process.

But you cannot overwrite global value. Only the local value (process' copy). Every other process (e.g. started by kubectl exec) will have "old" value of the env variable.

Upvotes: 1

Related Questions