Friday, April 27, 2018

Powershell Escape characters.

A while back I couldn't find a definitive list of the regular escape characters for PowerShell. So I wrote a program that would generate them all and give me a clue for each letter what I might get.

I have since lost the code, and the output was a little cryptic, particularly with nonprinting characters like Tab, space, Carriage return, Line feed, and Bell.

The Bell character "`a" was interesting. But it doesn't always make it back to me from a session.

The first 2 are for the quoting characters, if you need to embed a quote in the string you are creating, this is one easy way to get them placed literally, and not interpreted by the compiler.

As it was noted it the PluralSight Gotcha video, these are limited to Powershell, you will find if you pass a string to .net or some other software, it may have a different escape character, and different behavior.


Notes:
  • Single quote ' means that what is enclosed is Literal not to be processed
  • Double quote " means that what is enclosed is interpreted.
  • The Backtick is ` and not the single quote '  (apostrophe)
  • The key is typically on the left side of the keyboard upper left corner. 

PowerShell Escape character table:

ASCII
Letter
Esc
Name
Result ASCII
34
"
`"
Double Quote
34
39 
' 
`'
Single Quote
39
48
0
`0
Null
00
96
`
``
Back-tick
96
97
a
`a
Bell
07
98
b
`b
Backspace
08
102
f
`f
Line Feed
12
110
n
`n
New Line
10
114
r
`r
Carriage Return
13
116
t
`t
Tab
09
118
V
`v
Vertical tab
11

*   They are Case Sensitive...  "`n" -ne  "`N"  etc. 


No comments:

Post a Comment