4

Is it possible to call javascript inside a shell script? For example,

echo "Content-type: text/html"
echo "
     <html>
     <script type="text/javascript">
     document.write("<p>" + Date() + "</p>");
     </script>
     </html>
     "
1
  • What would you expect to happen if you could? This could be answered in so many different ways depending on what you're trying to do. Commented May 11, 2011 at 14:18

4 Answers 4

3

By default: No. But you could install applications that can run javascript like node.js or rhino.

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

1 Comment

It's also possible to start a node.js script from a shell script using the command node name_of_script.js.
2

If your script is used by CGI (Common Gateway Interface) application, then yes, you can include HTML with embedded JavaScript.

EDIT: JavaScript is a client-side technology. You won't get any trace of JavaScript running on server, because it won't be executed on server (unless we're talking about Server Side JavaScript but I don't think so).

1 Comment

@thetux: I'm not sure what you're trying to achieve - see my comment.
1

Try RhinoShell.

Comments

1

You'll need to install a javascript engine on your system to be able to call it from bash and execute your javascript code. Check SpiderMonkey.

1 Comment

After searching our forums a little, I found out that your question might be too related to this one: stackoverflow.com/q/2283234/176769

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.