Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The environment PATH while running inside WSL vs. running via bash -c differs #2634

Closed
freeman42x opened this issue Nov 4, 2017 · 11 comments

Comments

@freeman42x
Copy link

Microsoft Windows [Version 10.0.16299.19]

Problem: the environment PATH while running inside WSL vs. running via bash -c differs.

In WSL:

neo@razvan-pc:~$ echo $PATH$
/home/neo/.nix-profile/bin:/home/neo/.nix-profile/sbin:/home/neo/bin:/home/neo/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:windows paths following$

Via bash -c:

K:\Sources\haskell-ide-engine>bash -c "echo $PATH$"
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `echo /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files (x86)/Microsoft SDKs/Azure/CLI2/wbin:windows paths following$'

For example /home/neo/.local/bin/ is available under WSL but not under bash -c

I'd expect the paths should be the same or there should be some way to run something equivalent to bash -c so that the environment PATH is the same (at least the Linux bit of the path).

PS: Not sure what is the deal with syntax error near unexpected token ('`

@freeman42x
Copy link
Author

Running using bash --login -c allows the programs under that missing path to work:

K:\Sources\haskell-ide-engine>bash --login -c "which hie"
/home/neo/.local/bin/hie

K:\Sources\haskell-ide-engine>bash --login -c "hie"
2017-11-04 18:37:00.8238288 [ThreadId 11] - Setting home directory:/home/neo
2017-11-04 18:37:00.8268949 [ThreadId 11] - run entered for HIE Version 0.1.0.0, Git revision 1aae7c35e86c603d587ce3f3e57460d7a7e40f7a (dirty) (1058 commits) x86_64
2017-11-04 18:37:00.8314206 [ThreadId 11] - Current directory:/home/neo

But the path is still not echo'ed when running bash --login -c "echo $PATH$":

K:\Sources\haskell-ide-engine>bash --login -c "echo $PATH$"
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `echo /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:other windows paths$'

@Biswa96
Copy link

Biswa96 commented Nov 4, 2017

Try to use $PATH( not use $PATH$).

@freeman42x
Copy link
Author

@Biswa96 They both seem to work the same under WSL.
Under windows they both print the error: /bin/bash: -c: line 0: syntax error near unexpected token ('`

@therealkenc
Copy link
Collaborator

#2196 #2531 #2383 et al.

bash -c "echo \"$PATH\""

@freeman42x
Copy link
Author

@therealkenc why does echoing the path via bash -c require quotes but it does not require quotes and runs just fine when called directly through WSL?

@therealkenc
Copy link
Collaborator

For the same reason the following does the same thing on Real Linux. Because it is a syntax error.

export FOO="hello ("
ssh localhost "echo $FOO"

@freeman42x
Copy link
Author

@therealkenc if it is a syntax error why does echo $PATH work fine under WSL?
If it is a syntax error it should NOT work under WSL either.
So there is a WSL compatibility bug is what you are saying?

@freeman42x
Copy link
Author

Closing the issue since bash --login -c seems to solve the problem by running the login scripts.

@freeman42x
Copy link
Author

freeman42x commented Nov 5, 2017

@therealkenc So there is a WSL compatibility bug is what you are saying? Ehm, no, it works just fine on Real Linux also:

[root@nixos:/home/neo]# echo $PATH
/home/neo/bin:/run/wrappers/bin:/home/neo/.local/bin:/etc/per-user-pkgs/neo/bin:/home/neo/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

Both on root and non-root.

@therealkenc
Copy link
Collaborator

therealkenc commented Nov 5, 2017

why does echo $PATH work fine under WSL?

Because that is not a script with a syntax error at line 0. $PATH has already been expanded. Even simpler from Real Linux:

~$ export FOO="hello ("
~$ bash -c "echo $FOO"

Or even just:

~$ echo hello (

@freeman42x
Copy link
Author

@therealkenc Ok, I understand now, bash is a command usable from WSL/Linux also and that is the way expansion works. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants