question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remote SSH incorrectly strips empty but defined environment variables from shell environment

See original GitHub issue

VSCode Version: 1.63.2 SSH Remote extension latest preview (v0.71.2021121615 Pre-Release) Local OS Version: Fedora 35 Remote OS Version: CentOS 7.9 Remote Extension/Connection Type: SSH

Consider the following setup in your SSH config:

Host slpcomp1-prj
  HostName slpcomp1
  User mkrause
  ForwardX11 yes
  RemoteCommand bash -c "export TESTVAR1=HELLO; export TESTVAR2=HITHERE; export TESTVAR3; bash"

And connect to this node using this config with the SSH Remote Extension with RemoteCommand enabled.

Result: image

TESTVAR3 is incorrectly missing from the environment. This can be a problem if e.g. certain paths prefixes are encoded in such variables and on some machines they are intentionally empty. The behavior does NOT change if TESTVAR3 is defined as an empty string like so export TESTVAR3=""

I think I also understand why: For VS Code itself the variable most probably does exist, but not inside the terminals that are spawned. Reason seems to be the PTY bootstrap script that is launching the Terminal shells:

image

The red arrow shows the actual bash shell in which VS Code is running remotely for the correct environment. The green arrow displays the actual Terminal bash shell embedded inside VS Code. The blue arrow points to the bootstrap Javascript processes which according to what I was able to see somehow post-process the environment and seem to strip those defined but empty variables from the env before the bash is spawned.

This needs to be fixed.

/cc @mhoeher

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
roblourenscommented, Dec 6, 2022

In the OP, it sounds like @markusdd has identified that the variables are removed by the ptyHost

2reactions
markusddcommented, Feb 4, 2022

please reopen this is not solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I preserve an environment variable across su
Is there a way to preserve this variable (as well as other LC_xxx variables) when executing a login shell as another user on...
Read more >
bash - Why can't I specify an environment variable and echo it ...
The trouble is that the parent shell evaluates $SOMEVAR on the command line before it invokes the command with the modified environment. You...
Read more >
'xterm-kitty': unknown terminal type · Issue #713 - GitHub
I'm having an issue when connecting to remote server (onto which kitty is not installed). From kitty, if I ssh to the remote...
Read more >
Why I can't permanently remove these environment variables ...
1 Answer 1 · Make sure the envvars aren't being set by /etc/profile or /etc/profile.d/*. · Make sure they're not being set by...
Read more >
5.2. Environment Variables
If you're using a shell as your programming language, you can use the ``/usr/bin/env'' program with the ``-'' option (which erases all environment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found