I would like to the the windws8/cygwin/bash shebang feature to start a powershell script.
I do a "chmod +x set-sound.ps1"
and then at a bash prompt I do
./set-sound.ps1
The first line of ./set-sound.ps1
#!powershell.exe -ExecutionPolicy unrestricted
The result is the result:
./set-sound-output.ps1
At line:1 char:33
+ "-ExecutionPolicy unrestricted" ./set-sound-output.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~
Unexpected token './set-sound-output.ps1' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : UnexpectedToken
Compilation finished at Mon Feb 18 09:52:59
The problem is that powershell needs this strange switch so it will execute (it is a mystery to me why this is not the default).
Can someone help me configure bash so it can use the shebang to start powershell?
Thanks
Siegfried
#! lines must have absolute path /*
OK, good to know! Thanks. But it still does not work. Any more ideas? I did this from bash:
chmod +x ./hello.ps1
./hello.ps1
and still received this response:
At line:1 char:33
+ "-ExecutionPolicy unrestricted" ./hello.ps1
+ ~~~~~~~~~~~
Unexpected token './hello.ps1' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : UnexpectedToken
hello
Process compilation finished
Here is the source code:
#!c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe "-ExecutionPolicy unrestricted"
write-host "hello"
In Cygwin, "c:\" is "/cygsrive/c/".
Thanks again DGPickett! I'm still getting the same error, however.
#!/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy unrestricted
write-host "hello"
Here is the error:
-ExecutionPolicy : The term '-ExecutionPolicy' 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
+ -ExecutionPolicy unrestricted ./hello.ps1
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-ExecutionPolicy:String) [], Co
mmandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Process compilation finished
#! only accepts 1 argument. You can make a bash shell script that calls it.