Skip to content

How to pass environment variable if it is an array #995

@ddimitrioglo

Description

@ddimitrioglo

  • Version: v6.11.4
  • Platform: Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

Let's assume that we have test.sh with content:

for item in "${list_variable[@]}"; do echo ${item}; done

and we have test.js

'use strict';

const { exec } = require('child_process');

let env = {
  list_variable: ['one', 'two', 'three']
};

exec('bash test.sh', { env }, (error, stdout) => {
  console.log(stdout);
});

I expect to see

one
two
three

but receiving: one,two,three

Please help me understand the root cause..

P.S. Guys from https://github.com/nodejs/node redirected me here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions