Monday 1 May 2017

Correct quoting by executing shell script in nodejs

If I execute script.sh from the following example:

var spawn = require("child_process").spawn;
var dash = spawn('dash',['/path/to/script.sh','3']);

dash.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

dash.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

dash.on('exit', function (code) {
  console.log('child process exited with code ' + code);
});

I got an error:

stderr: cat: '*.pgn': No such file or directory

child process exited with code 0

This error belongs to the second line from script.sh

cat -n *.pgn | grep -o "1\.[a-zA-Z0-9. +]* $1\." > $RESULT

I suppose the error comes with respect to the quoting in the shell script. How to parse quotes in shell scripts before execution?



via Hölderlin

No comments:

Post a Comment