-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Steps to reproduce
This is a symptom of #4217, which was closed due to inactivity. Per "reopen a new issue and reference this issue if this is still a blocker for you", I am submitting this bug report as an example of why this issue is not simply cosmetic and needs to be fixed.
On UNIX based operating systems it is common to create user friendly aliases to commands using symbolic links. Symbolic links should not result in functional changes to script behavior, barring the case where the script itself is evaluating the name of the command used to invoke it (similar to what busybox does). The opposite applies here: a script cannot even test for its own name when the bug presents itself.
Expected behavior
Create a file named test.ps1 with the following contents:
#!/usr/bin/env pwsh
$PSCommandPath
$PSScriptRoot
$MyInvocationMake the script executable and create a symbolic link to test.ps1 that does not contain a suffix of ".ps1":
chmod 755 test.ps1
ln -s test.ps1 test
The output of the script should be identical regardless of how it is invoked. Invoking the script on its own yields the expected result:
PS /tmp> ./test.ps1
/tmp/test.ps1
/tmp
MyCommand : test.ps1
BoundParameters : {}
UnboundArguments : {}
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 5
ScriptName :
Line : ./test.ps1
Statement : ./test.ps1
PositionMessage : At line:1 char:1
+ ./test.ps1
+ ~~~~~~~~~~
PSScriptRoot :
PSCommandPath :
InvocationName : ./test.ps1
PipelineLength : 1
PipelinePosition : 1
ExpectingInput : False
CommandOrigin : Runspace
DisplayScriptPosition :Actual behavior
The output changes because the absence of a ".ps1" extension resulted in the invocation information not being populated. (#4217)
PS /tmp> ./test
MyCommand : #!/usr/bin/env pwsh
$PSCommandPath
$PSScriptRoot
$MyInvocation
BoundParameters : {}
UnboundArguments : {}
ScriptLineNumber : 0
OffsetInLine : 0
HistoryId : 1
ScriptName :
Line :
Statement :
PositionMessage :
PSScriptRoot :
PSCommandPath :
InvocationName :
PipelineLength : 2
PipelinePosition : 1
ExpectingInput : False
CommandOrigin : Runspace
DisplayScriptPosition :Error details
No response
Environment data
Name Value
---- -----
PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Ubuntu 22.04.4 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Visuals
No response

