1

I don't understand why in some cases it's ok to have spaces in parameters and in some cases it's not.

In this example it's ok to have spaces in $file variable, but not in $path.

$file = "test file.tar"
$path = "a b\"
New-Item -Path $path -Type Directory
# Make an empty tar file
tar -cf $file -T NUL
# extract it to $path
tar -xf $file -C $path

Gives you

tar.exe: could not chdir to 'a b"'

And most bizarre

tar -xf $file -C `"$path

works just fine.

I'm on Windows 11 and using the default PowerShell 5.1.

Iterokun
  • 184
  • 6
  • 1
    You're seeing a Windows PowerShell bug that has since been fixed in PowerShell (Core) 7+: a string with spaces that ends in ``\`` is incorrectly passed to external programs in that the necessary _escaping_ as ``\\`` in the - of necessity - double-quoted string that is used behind the scenes isn't performed. See the linked duplicate for details. – mklement0 Apr 20 '23 at 15:53

0 Answers0