running javascript on the command line

2

I'm a sucker for javascript, and i'm increasingly drawn towards writing script utilities for my everyday needs.

Currently I writing these utilities in bash scripts, but i'm not so proficient with shell scripting. I'm wondering if

  • any of you have ever come across an interpreter for javascript
  • any other convenient language that you use to write script utlitities in (like csh/perl)

[migrated from p.se]

I got one answer on p.se about Rhino. Is there anyway to run spidermonkey as a js interpreter on linux (and optionally windows)?

Here Be Wolves

Posted 2010-10-13T09:07:49.853

Reputation: 211

I know that V8 has been used to create server-run instances of javascript apps, an example being Node.js. Maybe see how Node.js is invoked...? – Jonathan – 2010-10-13T09:39:22.367

Answers

1

It is definitely possible to run SpiderMonkey at the command line. Fedora for one includes it in the js package, and there is documentation that shows how to build it.

Do note that XML and DOM handling is actually provided by the browser, and you'll need something like XML for <SCRIPT> if you want to use them at the command line.

I still prefer Python or Bash scripts whenever appropriate though.

Ignacio Vazquez-Abrams

Posted 2010-10-13T09:07:49.853

Reputation: 100 516

0

You may look at javascript-interpreter-to-replace-python question from stackoverflow. Personally I would rather use Python/Ruby for system scripting.

Casual Coder

Posted 2010-10-13T09:07:49.853

Reputation: 3 614

0

try NodeJs

It has loads or modules to help writing scripts to run on command line. Here is one of the library that can be used to write task based command line tools.

https://github.com/cowboy/grunt

Gaurav Jassal

Posted 2010-10-13T09:07:49.853

Reputation: 121