如何通过SpiderMonkey命令行将参数传递给脚本? [英] How to pass arguments to a script through the SpiderMonkey command-line?

查看:117
本文介绍了如何通过SpiderMonkey命令行将参数传递给脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Debian上使用SpiderMonkey 1.8.5. 我正在使用

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.

我尝试了以下操作:

js -f <myScript> <1stArg>

但是SpiderMonkey会将这两个参数都视为要执行的不同脚本,因此会发送错误消息,指出< 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?

推荐答案

像这样:

在script.js中

In script.js

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

然后从系统外壳程序中:

Then from system shell:

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

这篇关于如何通过SpiderMonkey命令行将参数传递给脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆