schuelermine
schuelermine

Reputation: 2288

Do I need to or should I use backticks after equals signs in PowerShell?

Assume I write
$variablewithanunnecessarilylongname = verylongcommand -whichalsohas $alotoflongparameters | and-needstobe $pushedthrough -along $pipe.

When I break apart the command at =, it still works (I think). But should I add a backtick anyways?

Upvotes: 1

Views: 92

Answers (2)

Lee_Dailey
Lee_Dailey

Reputation: 7479

you should only use backticks when there is NO OTHER WAY. [grin]

why? because they are far too easy to overlook.

leaving one behind when editing can make your code wonderfully difficult to debug. also, if there is anything after the backtick other than a line ending ... you will just escape that, not the line end. imagine a dangling backtick followed by a space or a tab ... then imagine trying to figure out what the blithering blasted heck is wrong with your code.

you can line wrap after almost anything that PoSh knows will be followed by "more stuff". the most obvious is a pipe symbol, but it also includes most operators, commas, open parens, open braces, the dot operator, and lots of other things.

linked below is a lovely article that covers many of the ideas mentioned above ...

Get-PowerShellBlog: Bye Bye Backtick: Natural Line Continuations in PowerShell
https://get-powershellblog.blogspot.com/2017/07/bye-bye-backtick-natural-line.html

Upvotes: 4

js2010
js2010

Reputation: 27463

No............................

There's so many other ways to continue a line: https://get-powershellblog.blogspot.com/2017/07/bye-bye-backtick-natural-line.html

Upvotes: -2

Related Questions