google / zx

A tool for writing better scripts

Home Page:https://google.github.io/zx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Quote does not work on Windows OS

cschuller opened this issue · comments

Expected Behavior

Works on Windows OS

Actual Behavior

Uses Unix/Linux quote syntax of $''

Steps to Reproduce the Problem

Run this script on Windows:

#!/usr/bin/env zx

const url = "https://example.com";

await $`echo ${url}`;

Expected
https://example.com

Actual
$'https://example.com'

Reason
$'' syntax is used in

zx/index.mjs

Line 319 in 7977cb5

return `$'`

Specifications

  • Version: 5.0.0
  • Platform: Windows 10, nodejs 16, npm 8

Options

  1. Make this tool OS independent
  2. Make the quote function configurable. (Document that Linux quote style is the default)
  3. Update READM.md and state that Windows is not supported.

@antonmedv I have read the doc and the source code.

Some more information:
The problem looks to be somehow related to the cmd.exe (Windows) version

#!/usr/bin/env zx

console.log(process.env.ComSpec);

const testUrl = 'https://example.com';
const data = await $`echo ${testUrl}`;
console.log(data.stdout);

OK Result (Windows Pro 10.0.19043)

C:\WINDOWS\system32\cmd.exe
$ echo $'https://example.com'
https://example.com
https://example.com

NOT OK Result (Windows Enterprise 10.0.19044)

C:\WINDOWS\system32\cmd.exe
$ echo $'https://example.com'
$'https://example.com'
$'https://example.com'

I understand if you don't have time to analyze or debug strange "Windows" problems.

I think in second case there bash installed somewhere in PATH. Which func detected it and set quota() func for quotation.

Possible solution override $.quota = noop