PowerShell for Windows Admins

Apr 30 2013   11:52AM GMT

Backticks are baaaaaad; don’t do backticks

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The voting/judging process has started for event 1 in the 2013 Scripting Games.  What I’m going to be doing over the next few weeks is point out some of the things that I’ve noticed when judging. Some will be good things that I think you should adopt; others will be bad things that you should avoid. There even may be some interesting stuff to get you thinking.

First off is the use of the backtick as a line continuation:

Get-Process | ` sort Handles –Descending

You don’t need a backtick at this point.  The pipe symbol acts as a line continuation marker so the backtick is redundant. All you need to do is this:

Get-Process | sort Handles -Descending

Its the same with commas. You don’t need to do this:

Get-Process | select Name, Id, ` Handles, CPU

because it works without the backtick

Get-Process | select Name, Id, Handles, CPU

You may see backticks used a lot in books but that is an attempt to reduce the width of the code to make it fit the page. We want you to be able to copy the code from the ebook and run it. The alternative is a line continuation marker which you would have to remove.

Bottom line – 99.9% recurring of the time you don’t need backticks as line continuation markers

2  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • zaphodikus
    0 pointsBadges:
  • zaphodikus
    The "other" 99% use case is that backticks are used to format args for a method that takes about 20 arguments, onto separate readable lines. Forgetting the parser expects a whitespace ahead of the backtick line-continuation character generates rather cruel parsing errors. Rare, but painful more than 1% of the time. :)
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: