简体   繁体   English

从 bash 脚本运行 javascript

[英]Running javascript from a bash script

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>

Thank you very much for anyone's help.非常感谢任何人的帮助。

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

How about using env like:如何使用 env 像:

my-file我的档案

#!/usr/bin/env node

console.log("hello from test file");

Make the file executable.使文件可执行。

chmod +x my-file

Then run it:然后运行它:

node my-file
hello from test file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM