Can't paste a comment (`#`) after a pipe (`|`) and a newline
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Paste the following 3 lines into PowerShell (same for Windows PowerShell and VS Code):
1..3 |
# I do 't expect an error here
ForEach-Object { $_ }
Expected behavior
No errors, the commented line (# ...
) to be neglected.
Similar to putting the comment directly after the pipe character:
1..3 | # I don 't expect an error here
ForEach-Object { $_ }
Actual behavior
Error
Error details
>> # I don 't expect an error here
ParserError:
Line |
1 | 1..3 |
| ~
| An empty pipe element is not allowed.
Environment data
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals

Issue Analytics
- State:
- Created a year ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Can't paste a comment (`#`) after a pipe (`|`) and a newline
Can't paste a comment (`#`) after a pipe (`|`) and a newline · Summary · Jobs. reminder · Run details. Usage · Workflow...
Read more >Commenting in a Bash script inside a multiline command
The reason $(#comment) doesn't work is because once it sees the # , it treats the rest of the line as comments, including...
Read more >How to get a new line at the end of pipe command
I'm having trouble to make the output of the following command to be all at the same line, and then have a new...
Read more >What's the point in adding a new line to the end of a file?
There are/were some C compilers that cannot parse the last line if it does not end with a newline. The C standard specifies...
Read more >Paste command in Linux with examples
Paste command is one of the useful commands in Unix or Linux operating system. It is used to join files horizontally (parallel merging)...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Indeed this relates to the specific pasting method being employed: simulated typing (which breaks) vs. pasting the multi-line string as a whole, and the issue is being tracked in:
To recap briefly:
As an aside: It is a separate issue, but it is curious that parsing stops after the comment line and considers the statement complete, given that it would make more sense to keep reading, based on the pending
|
.A more obvious example would be to try to paste the following (PS Core now allows placing the
|
on the next line):