Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell single quote vs double quote

I know that difference between using single quote instead of double quote is that variables aren't expanded.

$a = "hello"
"$a world"    # hello world
'$a world'    # $a world

I am accustomed to use double quote, but I guess that single quote could be more efficient. Is this always true? Is there some documentation about this topic? I googled a bit but results are overwhelmed by explanation about expanding variables

like image 807
Naigel Avatar asked Sep 08 '25 12:09

Naigel


2 Answers

Efficiency is very probably a non-issue if you don't have embedded variables or subexpressions.

A quick test with Measure-Command showed no difference at all.

like image 156
Joey Avatar answered Sep 11 '25 09:09

Joey


My preference is to use single quotes for anything that doesn't require expansion.

like image 27
Shay Levy Avatar answered Sep 11 '25 09:09

Shay Levy