How can I get the raw command line arguments in a node.js app, given this example command:
node forwardwithssh.js echo "hello arguments"
process.argv will be [ "node", "/path/to/forwardwith.js", "echo", "hello arguments" ]
And there's no way to reconstruct the original echo "hello arguments" from that (ie. join(" " won't put quotes back).
I want the whole original raw string after the script name.
what I want is easily obtained in bash scripts with "$*", is there any equivalent way to get that in node.js?
Note: the intention in particular is to receive a command to be executed somewhere else (eg. thru ssh)
"hello arguments",'hello arguments'orhello\ arguments. Those are all the same in bash. Do you want to just always assume that an arg with a space was originally quoted with double quotes? It's easy to see that the space must have been escaped somehow, because you get one arg instead of two for "hello arguments".process.argv.map(function(arg){ return '"' + arg + '"'; });. Which will give you:"node" "forwardwithssh.js" "echo" "hello arguments", which is the exact same in bash as your original command .--the arguments are parsed too. @Paulpro I can just add quotes to everything, I want to forward the raw argument as a command to be executed somewhere else