-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
After upgrading to 7.1.0, zx start powershell as shell instead of Bash #523
Comments
maybe still try to fix the problems with the "dollar" sign in The Linux world does not have posershell, and the commands in powershell and bash are different. Scripts are used on bash/sh in projects precisely because they can be used uniformly on different platforms without changes, and now we have to write scripts separately for Windows and all other platforms separately |
$ is not an error. It's bash special syntax for strings. Apparently, you used cmd.exe. For me it's much easier to add support for pwsh. Excaping in cmd.exe is bad. |
I wrote this after reading the contents of the last release, where this reason was given as the reason for switching to PowerShell |
Same issue, how to switch to bash forcibly? |
in every script write by hand if ( process.platform === 'win32' ) $.shell = 'bash' |
Actually we can check for bash on windows automatically too! |
Will do it. |
Fix https://github.com/google/zx/actions/runs/3202574452/jobs/5231685644 Try it:
|
it works! |
FYI, the new patch doesn't check if the bash is WSL or a TTY sim (like git bash). In my case, Apparently related to: #398 |
Is there a way to check it? We dan update the logic. |
We can check if the user is running under wsl by using microsoft/WSL#423 (comment) What's tricky is that there are several run cases:
Most user don't want the first, but they would want the 2nd. So it's really is a pairs checking for WSL and for maybe:
|
zx will use bash in wsl right now. |
Just to illustrate the difference between the cases I mentioned above, here's a specific example:
Invoking WSL bash under WSL VM is not the same as invoking WSL bash in the host's system - the tooling will have mismatch paths and side effects. I do think it is one hell of an abomination for a shell environment, but welp they did made WSL and people apparently love Windows
I think this sentence I made is a bit confusing. When the tooling has no side effect (like just a CLI that grep files for url), zx in both cases works fine. However, when there are side effect such as fs caching/fsmonitor (git case above, or pnpm global cache), it's important to differentiate where WSL bash is being run. Right now, zx uses WSL's bash under the host's environment (which introduces the example issue above) IF I run the zx script under the host environment. If I'm just testing zx inside a WSL VM, it works but then I'd rather bootup linux. |
I see. Let’s try to fix it. Maybe you can create a PR? |
After upgrading to 7.1.1, seems I'm hitting this problem. zx then uses my WSL bash shell by default, and doing a simple "yarn" command yields the error In other words, I still have to resort to the original hack ... :-D |
And what zx should us in this case? Powershell? |
Honestly, I'm not familiar with all this WSL / bash paths entanglement. louisgv seems much more clear about it. For me the hack is good enough. I'm just using Windows for development, but the final code will run on a Linux machine, so no big issues for me. |
Is there any progress? I expect to go to git bash by default on windows to run as a shell, most developers will install and use git, after all github needs it |
Well, windows does not have bash by default. Only powershell. |
Man, I almost lost my mind trying to figure it out. Thank you budarin, that did solve it for me. $.shell = 'C:\\Program Files\\Git\\bin\\bash.exe'; I think it must be at least noted in the main readme file that this package doesn't use bash. It would be better to set bash by default though. |
Bash is default by default. Unfortunately on windows everybody install bash in different ways. |
Never mind. I just noticed it is noted in the main page. 😄 |
What about checking what platform bash is built for, and skipping it if it is a Linux version when It would require 1 extra invocation of bash. Only using bash when PS> gcm -all bash
CommandType Name Version Source
----------- ---- ------- ------
Application bash.exe 10.0.1904… C:\WINDOWS\system32\bash.exe
PS> C:\WINDOWS\system32\bash.exe --version
GNU bash, version 5.1.16(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
PS> C:\WINDOWS\system32\bash.exe -c 'echo $OSTYPE'
linux-gnu
PS> C:\WINDOWS\system32\bash.exe -c '[[ $OSTYPE != "linux"* ]]' ; $?
False
PS> C:\WINDOWS\system32\bash.exe -c '[[ $OSTYPE == msys* || $OSTYPE == cygwin* || $OSTYPE == win32* ]]' ; $?
False
PS> & $env:USERPROFILE\AppData\Local\Programs\Git\bin\bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
PS> & $env:USERPROFILE\AppData\Local\Programs\Git\bin\bash -c 'echo $OSTYPE'
msys
PS> & $env:USERPROFILE\AppData\Local\Programs\Git\bin\bash -c '[[ $OSTYPE != "linux"* ]]' ; $?
True
PS> & $env:USERPROFILE\AppData\Local\Programs\Git\bin\bash -c '[[ $OSTYPE == msys* || $OSTYPE == cygwin* || $OSTYPE == win32* ]]' ; $?
True
PS> & $env:USERPROFILE\AppData\Local\Programs\Git\usr\bin\bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
PS> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.9
PSEdition Core
GitCommitId 7.2.9
OS Microsoft Windows 10.0.19045
Platform Win32NT |
Bash is a bad idea too, because Cygwin/MSYS2 argument parsing is not what nodejs/uvlib expects. Try to coax On the other hand at least you get the same shell to do loops with. That's good. |
Might not be very relevant, but I personally use the approach used by the C# port https://github.com/Cysharp/ProcessX where it does Windows -> "cmd /c", Linux -> "(which bash) -c". |
@Sojaner How do you handle the quoting issues with using It looks like Process X let an issue about how to include newlines go stale and get auto-closed. At a glance, it looks like they just ignore that |
@kcaswick You are correct! That's a big problem with cmd and it makes the scenarios for windows very limited. But that's the same with batch scripts! |
Fixed in v8. |
Expected Behavior
run Bash as shell
we share the project between Windows, MacOs and Linux platforms, and we can't write scripts for Windows and Linux separately (we have a lot of them)!
Actual Behavior
starts powerShell instead
Steps to Reproduce the Problem
while with zx@7.0.8 everything works well
Specifications
The text was updated successfully, but these errors were encountered: