Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unix: A script without .ps1 extension passed to the powershell binary lacks invocation information ($PSCommandPath, $MyInvocation), such as when invoked via a shebang line. #4217

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

Steps to reproduce

Create file ./t - note the absence of extension .ps1 - with the content below and make it executable (chmod +x ./t).

#!/usr/bin/env powershell

'$PSCommandPath: ' + $PSCommandPath
'$MyInvocation.MyCommand.Path: ' + $MyInvocation.MyCommand.Path
'$MyInvocation: ' + ($MyInvocation | Out-String)

Both the following invocation methods, from bash, yield the behavior described below:

./t  # invocation via shebang line
powershell ./t   # implied -File

Expected behavior

$PSCommandPath and $MyInvocation.MyCommand.Path should reflect the script's file path, and $MyInvocation should be populated appropriately.

Actual behavior

$PSCommandPath:
$MyInvocation.MyCommand.Path:
$MyInvocation:

MyCommand             : #!/usr/bin/env powershell

                        '$PSCommandPath: ' + $PSCommandPath
                        '$MyInvocation.MyCommand.Path: ' + $MyInvocation.MyCommand.Path
                        '$MyInvocation: ' + ($MyInvocation | Out-String)

BoundParameters       : {}
UnboundArguments      : {}
ScriptLineNumber      : 0
OffsetInLine          : 0
HistoryId             : 1
ScriptName            :
Line                  :
PositionMessage       :
PSScriptRoot          :
PSCommandPath         :
InvocationName        :
PipelineLength        : 2
PipelinePosition      : 1
ExpectingInput        : False
CommandOrigin         : Runspace
DisplayScriptPosition :

Environment data

PowerShell Core v6.0.0-beta.3 on macOS 10.12.5
PowerShell Core v6.0.0-beta.3 on Ubuntu 16.04.1 LTS
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productOS-LinuxOS-macOSResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.