Wednesday, June 23, 2010

Powershell Quick Hit - Text in quotes

I'm beginning to piece together the intricacies of text pattern matching using regex wildcards. It's tricky stuff, but that's not the point of this Quick Hit, it's just something interesting that I picked up along the way.

Today's Powershell quick Hit has to do with text in single or double quotation marks. Powershell treats each of them very differently, especially when variables and wildcards are being used.

Consider these 2 variable strings:

PS:\ $date = get-date
PS:\ $single = 'Today is $date, and my Windows Directory is $env:windir.'
PS:\ $double = "Today is $date, and my Windows directory is $env:windir."
PS:\ $single
Today is $date, and my Windows Directory is $env:windir.
PS:\ $double
Today is 06/23/2010 22:51:00, and my Windows directory is C:\WINDOWS.

No comments:

Post a Comment

Are you in favor of irradating food?