How to pass arguments to a script through the Spid

2019-09-17 14:27发布

问题:

I am using SpiderMonkey 1.8.5 on Debian. I am starting a script through the command-line using

js -f <myScript>

I'd like to pass some arguments to my script, but I don't know how to do that. It's supposedto be possible since the documentation tells you about a special object gathring all parameters provided to a script.

I tried the following:

js -f <myScript> <1stArg>

But SpiderMonkey consider both parameters as different scripts to execute and thus sends en error saying the '<1stArg>' file doesn't exist.

What is the correct way to do what I wish?

回答1:

Like this:

In script.js

#!/usr/bin/js
print(arguments);

Then from system shell:

$ chmod +x script.js
$ ./script.js