8

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?

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

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

Thank you very much for anyone's help.

2
  • Node? nodejs.org Commented Jun 12, 2014 at 11:37
  • Possible duplicate of stackoverflow.com/questions/2283234/…, but the answers are largely 4 years old and several are no longer useful. Commented Jun 12, 2014 at 11:41

2 Answers 2

21

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

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

To run a script: $ node script.js

Sign up to request clarification or add additional context in comments.

Comments

4

How about using env like:

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

2 Comments

I did run the script directly without calling node at first like this: ./myfile.js
Yeah. I 2nd that. You don't have to use node after you supply the REPL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.