Running powershell script inside a bash script
In Powershell-
How do I run a powershell script(.ps1) inside a bash script(.sh)
I can run just the powershell script-
& .\scriptfile.ps1
and just the bash script.
But when I try to run the powershell inside the bash script, I get
file.ps1 : command not found
Both scripts are in the same path.
Solution 1:
Are you trying
.\scriptfile.ps1
? That should be
./scriptfile.ps1
But also, when invoking powershell from a bash script, you'll need to either run the pwsh command like
pwsh ./scriptfile.ps1
or the first line of your Powershell script file should be a shebang (interpreter directive) like:
#!/usr/bin/env pwsh
See How can I use a shebang in a PowerShell script?
Solution 2:
I'm using git bash on Windows 10 Pro and there it's powershell
.
The executable is in /c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe
and it's contained in my $PATH
.
So I can say
powershell ./scriptfile.ps1
# or inline:
powershell 'my script'
In the Ubuntu-on-Windows bash I have to say
powershell.exe ./scriptfile.ps1