I have an existing screen session and now I need to set some (more than one) environment variables to that session. These environment variables should not be visible to other screen sessions. I tried the solution in this answer which didn't work.

I tried

screen -r "myscreen" -X setenv x x_value;y y_value;z z_value

Here I got an error

-bash: x: command not found
-bash: y: command not found

then I tried

screen -r "myscreen" -X setenv x x_value;setenv y y_value;setenv z z_value

which gave me

-bash: setenv: command not found
-bash: setenv: command not found

How can I set multiple variables at once?

  • 1
    Why don't you just run var=value in the running screen session? – terdon Sep 28 '20 at 12:07

instead of setenv command, try export command

export myEnvVar="echo \"It works!\""

bash $~/ $myEnvVar

Output: It works!

To make it permanent for your user: in the .bashrc file (usually your your /home//folder) add it at the last line, and reload the bash shell.

I.e you could add the following lines:

export myEnvVar="echo \"It works\""
echo $myEnvVar

And to reload the bash shell - reopen it(the terminal) or just type bash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.