01 August 2012

Difference between single quote and double quote

 ' vs "
It is a known best practice in powershell to use double quotes only when is necessary;
Only between double quotes powershell will:

  • look for the backtick ` excape character and interpret the sequence properly;
    Example: `t will insert a tab; `n will insert new line;
  • look for the dollar $ character and interpret what follows as the name of a variable and replace the variable name with the variable content.
    Example: if $cars = 10;
    "number of cars is $cars" became: "number of cars is 10" 
These rules don't apply to single quotes and this is why is a best practice to only use double quotes only when needed;

No comments:

Post a Comment