制作一个接受命令行参数的脚本 [英] Make a script which accept command-line arguments
本文介绍了制作一个接受命令行参数的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Linux或Mac上运行带有命令行参数的Node.js脚本的正确语法是什么?
What is the correct syntax for running a Node.js script with command-line arguments on Linux or Mac?
要在没有参数的情况下运行脚本,只需使用命令 node stuff.js
,但在这种情况下,我想运行一个名为 stuff.js $ c $的脚本c>带有参数
blah, hee, woohoo! 。
To run the script with no arguments, I would simply use the command node stuff.js
, but in this case, I'd like to run a script called stuff.js
with the arguments "blah", "hee", "woohoo!"
.
推荐答案
请参见 http://nodejs.org/docs/latest/api/process.html #process_process_argv
总而言之,您将像
节点stuff.js等等 whoohoo!
然后,您的参数在 process.argv $中可用c $ c>
这篇关于制作一个接受命令行参数的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文