It seems that several commands like 'find' and 'which' (and surely others) are overridden by the git-bash versions if you launch powershell inside git-bash:
raw powershell (expected)
Which doesn't exist:
(base) PS C:\> which
which : The term 'which' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:1
+ which
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (which:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
'which find' does nothing:
(base) PS C:\> which find
which : The term 'which' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:1
+ which find
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (which:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Find runs windows version:
(base) PS C:\> find
FIND: Parameter format not correct
(base) PS C:\> find --help
FIND: Parameter format not correct
Powershell inside Git Bash (broken)
launch powershell:
user@PC0 MINGW64 ~
$ powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
Loading personal and system profiles took 614ms.
'which' exists and is git-bash version:
(base) PS C:\> which
Usage: /usr/bin/which [options] [--] COMMAND [...]
Write the full path of COMMAND(s) to standard output.
--version, -[vV] Print version and exit successfully.
... (omitting the rest of the usage)
'which' confirmed as /usr/bin/ version:
(base) PS C:\> which which
/usr/bin/which
'find' confirmed as /usr/bin/ version via 'which':
(base) PS C:\> which find
/usr/bin/find
'find' giving git-bash usage inside powershell:
(base) PS C:\> find --help
Usage: /usr/bin/find [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression]
Default path is the current directory; default expression is -print.
Expression may consist of: operators, options, tests, and actions.
... (omitting the rest of the usage)
I am launching a powershell script by running it inside powershell.exe from my git-bash shell. It completely breaks the script because I use the windows version of 'find' but it ends up using the git-bash version of find which doesn't work the same.
Why is this happening?
How can I fix it?
Edit:
It seems PATH is inherited and being used by powershell, if I set PATH= then launch powershell via /c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
It seems to fix it partially.
If I do that then commands like xcopy stop working, I guess they need powershell's default PATH.
I can grab my powershell path from $Env:Path and I can assign that to PATH before running powershell and it seems to fix everything.
This is not a dynamic solution though, how can I make it dynamic so it will work on anybody's PC without needing to know their default PATH?