I want to be able to tell whether a shell calling my script is either bash or powershell. I’ve attempted to do this via $MyInvocation
and seeing the $PPID
, but neither give any clues.
test.ps1
#!/bin/pwsh
$MyInvocation
[System.Diagnostics.Process]::GetCurrentProcess().Parent
Here I first run a script from a bash interactive session, then immediately from a powershell instance. They aren’t really distinguishable, I do understand why, but is there a way this can be done?
1