PSS 2016 5.2.117 - Problem with wordwraps

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 5 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

PSS 2016 5.2.117 - Problem with wordwraps

Post by monoeagle »

Product, version and build: PSS 2016 5.2.117
32 or 64 bit version of product: x64
Operating system: Win7
32 or 64 bit OS: x64

Hi,

If I use "`" to wrap the line for better reading.
Bildschirmfoto 2016-03-22 um 16.45.16.png
Bildschirmfoto 2016-03-22 um 16.45.16.png (51.85 KiB) Viewed 5876 times
Sometimes it results in an Error. The Second Block is written as the first one.
Bildschirmfoto 2016-03-22 um 16.45.31.png
Bildschirmfoto 2016-03-22 um 16.45.31.png (20.13 KiB) Viewed 5876 times
If I remove all wordwraps the errors disappears, but the reading ... ;(.


That what I can reproduce is if the ` is without a space behind a String all is OK.
But if the `is without a space behind a variable the Error occours.

regards
mono
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by DevinL »

I've moved this post to the PowerShell forum so others can chime in as well.

While I can't find anything that directly states PowerShell requires a space before the escape character, the about_Escape_Characters file (https://technet.microsoft.com/en-us/lib ... 47755.aspx) has a space in the example for Line Continuation. If you were to take out that space, it won't work in a standard PowerShell console either.
DevinL
SAPIEN Technologies, Inc.
User avatar
juneblender
Posts: 93
Last visit: Thu Mar 30, 2017 8:54 am

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by juneblender »

I suspect that you're right. I wrote about_Escape_Characters and, sadly, never thought to test the spaces before or after. We've learned that a space AFTER the backtick makes it ignored. I haven't seen any comments about a space before, but I've just tested it on a few cases (not conclusive).

I'm going to tweet this question to the PowerShell team (@PowerShell_Team) and Jason Shirk, the PS language dev, and get you a definitive answer. We should also do a User Voice request to update the help topic with this new information. Feel free to chime in.

https://twitter.com/juneb_get_help/stat ... 4743410688

Thanks so much for your post.
User avatar
juneblender
Posts: 93
Last visit: Thu Mar 30, 2017 8:54 am

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by juneblender »

Just got the definitive answer from Windows PowerShell MVP Kirk Munro (@poshoholic).

Preceding space required only if preceding token does not have enclosures. Otherwise the backtick becomes part of the preceding token rather than a continuation char. By enclosures I mean quotes, brackets, array/hashtable/multi-line comment enclosures, etc. By token I mean an unquoted value (string, numeric, etc.). e.g. gsv wuauserv` (in token).

I've filed a User Voice bug to update about_escape_characters: https://windowsserver.uservoice.com/for ... syntax-req
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by monoeagle »

Hi June,

I don't use Twitter but read the answers. Thanks for your post.

The solution is to use enclosures to prevent this problem? =)

regards
mono
(Tobias Philipp)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by jvierra »

There is a much better method that is also very powerful. Splatting.

help about_splatting
  1. #to splat a command
  2. $mysplatr = @{
  3.     From = 'me@home.net'
  4.     To = 'Me@work.org'
  5.     Subject = 'The subject'
  6.     SMTPServer = 'smtp.giggle.com'
  7.     Port = 587
  8.     BodyAsHtml=$true
  9. }
  10. $body = '>h1>Hello world</h1>'
  11. Send-MailMessage @mysplatr -Body $body
User avatar
OldLost
Posts: 55
Last visit: Wed Feb 21, 2018 8:00 am

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by OldLost »

A bit of an aside, but this highlights two things that might enhance PSS for some:
  • A way to show hidden characters in the script (space and tab, specifically)
  • An entry in the toolbar that would remove all trailing spaces/tabs from the file
If these options are already present, I'm not aware of them.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by jvierra »

The PSS reformatter will do most of that and the syntax checker should catch most other issues. The backtic is an outlier which is why most of us recommend against its use and use splatting when necessary.

The line continuation is almost never needed. It was hotly debated when included in PowerShell but those who were used to BASIC wanted it so we are stuck with it. Just don't use it. It is very prone to breakage.
User avatar
monoeagle
Posts: 108
Last visit: Fri Jan 26, 2024 10:44 am

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by monoeagle »

Thanks for the splatting example/hint.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PSS 2016 5.2.117 - Problem with wordwraps

Post by jvierra »

You are welcome.
It makes things much easier.
This topic is 8 years and 5 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked