The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

AHodsdon (4) [Avatar] Offline
#1
I've encountered some behavior in powershell that I can't understand:

PS C:UsersAHodsdon> $a = "hello"
PS C:UsersAHodsdon> $b = "`"$a`""
PS C:UsersAHodsdon> cmd.exe "/c echo $b"
"hello""

Why is there the second quote mark after hello? I've found I can get rid of it by just eliminating the all the quotes on line 3, but I'm still curious what's going on.
AHodsdon (4) [Avatar] Offline
#2
Re: Quoting question
Even simpler example:

PS C:UsersAHodsdon> $b = "hello"
PS C:UsersAHodsdon> cmd.exe "/c echo $b"
hello"
AHodsdon (4) [Avatar] Offline
#3
Re: Quoting question
Hmmm... the same thing happens with the trivial command:

PS C:UsersAHodsdon> cmd "/c echo foo"
foo"

Indeed, I get the same result if I'm running in cmd and not using PowerShell at all.
It looks like cmd ignores anything that comes before the /c:

PS C:UsersAHodsdon> cmd "this doesnt do anything /c echo foo"
foo"

The thing that really confused me was that PowerShell would't let me not have the ending quote:

PS C:UsersAHodsdon> cmd "this doesnt do anything /c echo foo
>>
>> "
>>
foo