npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Parsing of an escape sequences is not working in scripts

What I Wanted to Do

I tried to echo the following script when someone tries to npm test:

"test": "echo -e '\\e[31mError\\e[0m: No tests specified!\n Go totemplates/additiveand runnpm testthere.' && exit 1",

I expected to see the Error coloured in red.

What Happened Instead

-e \e[31mError\e[0m: No tests specified!

Reproduction Steps

Add the above snippet to the scripts section

Platform Info

$ npm --versions
{ npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.11.4',
  openssl: '1.0.2p',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }
$ node -p process.platform
darwin


Seems like sh acts differently than I would expect.

$ sh -c "echo -e 'fo\u0308o'"
-e fo\u0308o

$ echo -e 'fo\u0308o'
föo

$ bash -c "echo -e 'fo\u0308o'"
föo

Edit: no, that’s expected behavior. The built-in echo in dash doesn’t have a -e flag.

Workaround: you can set a different shell (like bash) manually with npm config set script-shell $PATH.


Oh okay, I’m sad to hear that. Will this be implemented to dash?
Thanks for the workaround and the fast response!


No, it’s defined like that in the POSIX standard (link) and use of printf is recommended instead. More info.


Thank worked!! Thanks :slight_smile: