I have a text file where each line is a list of arguments I want to pass to a nodejs script. Here's an example file, file.txt:
"This is the first argument" "This is the second argument"
For demonstration's sake, the node script is simply:
console.log(process.argv.slice(2));
I want to run this node script for every line in the text file, so I made this bash script, run.sh:
while read line; do
node script.js $line
done < file.txt
When I run this bash script, this is what I get:
$ ./run.sh
[ '"This',
'is',
'the',
'first',
'argument"',
'"This',
'is',
'the',
'second',
'argument"' ]
But when I just run the node script directly I get the expected output:
$ node script.js "This is the first argument" "This is the second argument"
[ 'This is the first argument',
'This is the second argument' ]
What's going on here? Is there a more node-ish way to do this?