mkdir folders via array [npm scripts]

Using npm scripts,

// package.json

“scripts”: {
“folder”: “mkdir -p {foo,bar}”
}

Running mkdir -p {foo,bar} on the command prompt directly would make 2 directories: foo and bar
However, npm run folder just creates a folder named {foo,bar}

Why is that? How do I go about achieving this?

It worked as you expected for me with a bash shell, so it may be the shell used for your scripts. You could run env from a script and check what shell is active.

The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe . The actual shell referred to by /bin/sh also depends on the system. As of npm@5.1.0 you can customize the shell with the script-shell configuration.

And the simple way you could create two directories without relying on which shell is:

mkdir -p foo && mkdir -p bar

I am using bash:
"env": "env | grep SHELL" in package.json, running npm run env gives the following output

GNOME_SHELL_SESSION_MODE=ubuntu
npm_package_scripts_env=env | grep SHELL
npm_lifecycle_script=env | grep SHELL
SHELL=/bin/bash

I am on Mac, although not sure why that would make a difference. Are you seeing any quoting on the command? I see:

$ npm run
...
  try
    mkdir {foo,bar}
$ npm run try
...
> mkdir {foo,bar}
$ ls
bar		foo		package.json

(I have not done much with shell details. Most of my projects are cross-platform, so my package.json scripts are very portable.)

No, no quotes.
As I said, entering directly in shell works, but not via scripts

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.