Annoying apostrophe issue in Powershell

Of course it is not annoying if someone can accept this escape character and as matter as the fact it is bit better that the divide sign (/) but even I say I am always suffering about this.

Let’s see what I am talking about:

$var = Get-ChildItem -Name C:\

foreach ($work in $var) {Write-Host “<a href=”http://site/list/$work”>$work</a>&#8221;}

The result is not exactly what I really waited. It is not working because of the quotation mark around the http:// tag.

After I tried this one:

foreach ($work in $var) {write-host <a href=http://site/list/$work‘”>$work</a>}

With this I got the following: <a href=”http://site/list/ File”>File</a>

wrong example
Wrong Example

Can you see that space between the list/ File? No? I can see and this is the reason why I am so angry. But there is a good news: there is solution.

Forget the things above and use the following form if  you want to get a proper list:

foreach ($work in $var) {write-host “<a href=`”http://site/list/$work`”>$work</a>”}

quick evidence
Quick Evidence

What is the trick? Grab your chair. This one: ` (Alt Gr + 7)

Have fun!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s