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
    Commented Sep 28, 2020 at 12:07

1 Answer 1


instead of the setenv command, try the 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .