21

In terms of quick dynamically typed languages, I'm really starting to like Javascript, as I use it a lot for web projects, especially because it uses the same syntax as Actionscript (flash).

It would be an ideal language for shell scripting, making it easier to move code from the front and back end of a site, and less of the strange syntax of python.

Is there a good, javascript interpreter that is easy to install (I know there's one based on java, but that would mean installing all the java stuff to use),

Matthias Wandel
  • 6,383
  • 10
  • 33
  • 31

12 Answers12

13

I personally use SpiderMonkey, but here's an extensive list of ECMAScript shells

Example spidermonkey install and use on Ubuntu:

$ sudo apt-get install spidermonkey
$ js myfile.js
output
$ js
js> var f = function(){};
js> f();
valse-triste
  • 103
  • 4
Zach
  • 24,496
  • 9
  • 43
  • 50
  • 3
    `brew install spidermonkey` on OS X with homebrew installed. Love it. – prairiedogg Nov 05 '10 at 12:53
  • 3
    spidermonkey is not included in Ubuntu Lucid 10.04 :(. – Grzegorz Gierlik Dec 28 '10 at 19:49
  • @Grzegorz Gierlik: Via 'Lanuchpad' PPA, also for natty: [Best way to get spidermonkey js on Ubuntu 11.04?](http://stackoverflow.com/questions/6656904/best-way-to-get-spidermonkey-js-on-ubuntu-11-04/7291896#7291896) – sdaau Sep 03 '11 at 08:03
  • Link (burstproject.org) is inactive and seems to have reverted to horrible Go Daddy wall of links/ads. – John Carter Sep 24 '11 at 02:33
  • Someone else has saved a copy of that page. I'm substituting that link. It probably won't be up to date, but somethin'. – valse-triste Jan 11 '13 at 19:59
10

Of course, in Windows, the JavaScript interpreter is shipped with the OS.

Just run cscript or wscript against any .js file.

Frank Krueger
  • 69,552
  • 46
  • 163
  • 208
  • Too bad I think this approach doesn't offer an interactive shell session, can only run javascript files. – David May 17 '13 at 19:41
7

There are four big javascript interpreters currently. V8, Squirrelfish, Spidermonkey and Rhino. I think more important than performance is how well it integrates into existing infrastructure, and I guess Rhino with its bridge to Java wins here.

Armin Ronacher
  • 31,998
  • 13
  • 65
  • 69
4

Try jslibs, a scripting-focused standalone JS runtime and set of libraries that uses SpiderMonkey (the Gecko JS engine).

skymt
  • 3,199
  • 21
  • 13
2

On the 'easy to translate' theme, there's also Lua.

It's somewhat similar to Javascript, but more 'orthogonal' (closer to functional roots).

The heavy orientation to 'pure' programming theory has made it really small and fast. It's the fastest scripting language around, and the JIT runs circles around the new JavaScript JITs that are starting to appear.

Also, since it was originally thought as an extension language, it has a very nice and clean interface to C, making it very easy to create bindings to any C library you might want to access.

Javier
  • 60,510
  • 8
  • 78
  • 126
1

Google's V8 can be used as a standalone interpreter. Configuring with scons sample=shell will build an executable named shell, that can be called like so: ./shell file.js.

Community
  • 1
  • 1
William Keller
  • 5,256
  • 1
  • 25
  • 22
1

You'll need some server-side JavaScript interpreter. Check out the following blog post. Something such as Rhino might be useful for you.

1

You might try toying around with SquirrelFish or v8, both should be runnable on the command line.

Florian Bösch
  • 27,420
  • 11
  • 48
  • 53
1

FYI, there is a built-in one already on modern windows platforms. You need to use JScript, but it's close enough. Same environment also allows for VBScript. To run a program you can execute something like:

cscript foo.js

The windows system API is a bit weird and frustrating if you expect the same flexibility as with basic JS objects, but they do have thorough documentation if you can handle digging through the MSDN pages and seeing all the examples in VBScript.

Not sure what's available for Linux/Mac in terms of js shell.

Glenn
  • 200
  • 1
  • 2
  • 6
0

Node.JS. It's great. Has many modules. you can do all your file scripting with Node.

erin100280
  • 39
  • 3
0

Well, for safety reasons, javascript had not been provided with file access right by design. So as a scripting language, it's a bit limited.

But still, if you really want to, spider monkey is your best option. Here is a tuto :

http://developer.mozilla.org/en/Introduction_to_the_JavaScript_shell

Bite code
  • 578,959
  • 113
  • 301
  • 329
-2

In my years I've found most Javascript developers find it quite easy to transfer over to PHP and vice versa - it isn't a direct answer to your question, although if you're working in ActionScript and JavaScript then you're best to stick with something like PHP (if you're not willing to move to Java, and stick with the ECMA base)

d2kagw
  • 155
  • 3
  • 9