Mam plik tekstowy, w którym każda linia jest listą argumentów, które chcę przekazać skryptowi nodejs. Poniżej znajduje się przykład pliku plik.txt:przekazywanie cytowanych argumentów do węzła za pomocą skryptu powłoki?
"This is the first argument" "This is the second argument"
Dla dobra demonstracja za skrypt węzeł jest po prostu:
console.log(process.argv.slice(2));
chcę uruchomić ten skrypt węzła dla każdego wiersza w pliku tekstowym, więc dokonaniu tego skryptu bash, run.sh:
while read line; do
node script.js $line
done < file.txt
Kiedy uruchomić ten skrypt bash, to co mam:
$ ./run.sh
[ '"This',
'is',
'the',
'first',
'argument"',
'"This',
'is',
'the',
'second',
'argument"' ]
Ale kiedy tylko uruchomić skrypt węzła bezpośrednio uzyskać oczekiwany wynik:
$ node script.js "This is the first argument" "This is the second argument"
[ 'This is the first argument',
'This is the second argument' ]
Co tu się dzieje? Czy istnieje bardziej węzłowy sposób na zrobienie tego?
dzięki! to wystarczyło – Rafael