从 bash 脚本运行 javascript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24183352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:40:01  来源:igfitidea点击:

Running javascript from a bash script

javascriptbash

提问by Sentinel

I am new to learning bash script programming and was wondering if anyone here knows how can I execute javascript that would normally be embedded into an html page?

我是学习 bash 脚本编程的新手,想知道这里是否有人知道如何执行通常会嵌入到 html 页面中的 javascript?

So from a bash script, I would like to execute ( for example ):

因此,从 bash 脚本中,我想执行(例如):

<script type="text/javascript" src="scriptName.js"></script>

<script type="text/javascript" src="scriptName.js"></script>

Thank you very much for anyone's help.

非常感谢任何人的帮助。

回答by joews

You'll need a Javascript runtime like Node.js.

你需要一个像Node.js这样的 Javascript 运行时。

To evaluate a snippet of code: $ node -e "console.log('hello')"

要评估代码片段: $ node -e "console.log('hello')"

To run a script: $ node script.js

要运行脚本: $ node script.js