Skip to content

Beta.9 - Module PSReadLine impacting ifelse block structure #575

Closed
@MaximoTrinidad

Description

@MaximoTrinidad

Current PowerShell behavior is to automatically load the PSReadLine module. But, this module is breaking the if-else block of code when using Copy/Paste into the PowerShell Console.

Steps to reproduce

  1. Open PowerShell "pwsh" Console.
  2. Copy/Paste the following code into the Console:
## - Code Snippet will verify if NuGet is already installed:
if (-not (Get-PackageSource | Where-Object{$_.Name -eq 'Nuget'})) 
{
    Register-PackageSource -Name Nuget -ProviderName NuGet -Location https://www.nuget.org/api/v2
}
else
{
    Write-Host "NuGet Already Exist! No Need to install."
}

Expected behavior

Process the code without errors.

Below, the results of executing the "if-else" block without errors, after executing "Remove-Module PSReadLine"

PS C:\Program Files\PowerShell\6.0.0-beta.9> if (-not (Get-PackageSource | Where-Object{$_.Name -eq 'Nuget'}))
>> {
>>     Register-PackageSource -Name Nuget -ProviderName NuGet -Location https://www.nuget.org/api/v2
>> }
>> else
>> {
>>     Write-Host "NuGet Already Exist! No Need to install."
>> }
>>
NuGet Already Exist! No Need to install.
PS C:\Program Files\PowerShell\6.0.0-beta.9>

Actual behavior

Paste code stopped executing after it reads the "else".

PS C:\Program Files\PowerShell\6.0.0-beta.9> if (-not (Get-PackageSource | Where-Object{$_.Name -eq 'Nuget'}))
>> {
>>     Register-PackageSource -Name Nuget -ProviderName NuGet -Location https://www.nuget.org/api/v2
>> }
PS C:\Program Files\PowerShell\6.0.0-beta.9> else
else : The term 'else' 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
+ else
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (else:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Program Files\PowerShell\6.0.0-beta.9> {
>>     Write-Host "NuGet Already Exist! No Need to install."
>> }

    Write-Host "NuGet Already Exist! No Need to install."

PS C:\Program Files\PowerShell\6.0.0-beta.9>
PS C:\Program Files\PowerShell\6.0.0-beta.9>

Environment data

OS:
Windows 10 Insider Build 1702
Ubuntu 16.04.3

PowerShell Core Beta.9

## - Windows PowerShell Core
PS C:\Program Files\PowerShell\6.0.0-beta.9> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Microsoft Windows 10.0.17025
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

## - Linux PowerShell Core
PS /home/maxt> $PSVersionTable                                                                                           

Name                           Value                                                                                    
----                           -----                                                                                    
PSVersion                      6.0.0-beta.9                                                                             
PSEdition                      Core                                                                                     
GitCommitId                    v6.0.0-beta.9                                                                            
OS                             Linux 4.10.0-38-generic #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017              
Platform                       Unix                                                                                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                  
PSRemotingProtocolVersion      2.3                                                                                      
SerializationVersion           1.1.0.1                                                                                  
WSManStackVersion              3.0

if-else_01_2017-11-06_18-25-39

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions