2
votes

I have an instance on Google computer engine, and i have exported environment variable running $ export my_token=my_token. Everything is fine, it prints my_token running $ echo $my_token.

But after closing ssh connection and reconnect to my instance and I try again to run echo $my_token, it prints nothing. Therefore I guess I've lost the exported environment variable after closing ssh.

  • How can i keep my environment variable even after closing ssh on a Google Compute Engine Instance?
1

1 Answers

1
votes

On a Compute Engine Instance it works exactly like any other Linux or Unix instance, from the Operating System point of view there is no difference.

Explanation

  • Setting an environment variable applies merely to the session, it is not persistent, each time you open a new shell (for example changing the user or connecting through ssh) you will lose the environment variable set in the previous one.

Solution

To keep a value of an environment variable that will be set in each new shell you start, you could add the export my_token=my_token command to one of your shell's init files. For example ~/.profile or ~/.bashrc.

Further References