Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Recently I've been working with JS and I'm very enthusiastic about this language. I know that there is node.js for running JS at server side, but is there a shell that uses JS as a scripting language? If such thing exists, how usable & stable is it?

share|improve this question
add comment

4 Answers 4

up vote 8 down vote accepted

Does this look desirable to you?

// Replace macros in each .js file
cd('lib');
ls('*.js').forEach(function(file) {
  sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
  sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file);
  sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file);
});
cd('..');

If so, ShellJS could be interesting, it's

a portable (Windows included) implementation of Unix shell commands on top of the Node.js API.

I'm unsure if this could be used as a full-featured login shell, though. (Maybe with some wrapping?)

You could argue that it's not really a shell, but do you know TermKit? It's made of Node.js + Webkit, you could use JS to extend it (I guess); the shell language is still Bash(-ish).

share|improve this answer
    
Well, that looks cool! I'll give it a try. –  J-unior Dec 9 '12 at 16:32
add comment

Mozilla INC offers a javascript shell : see Introduction_to_the_JavaScript_shell

Example of a shell in a system :

$ js
js> str = "welcome on *nix side" 
"welcome on *nix side"
js> str.indexOf("nix");          
12
js> 

No problems detected since I use it for testing purpose.

share|improve this answer
add comment

If you're on Ubuntu or any other debian based system, you may install rhino (from Mozilla.org).

sudo apt-get install rhino

It supplies js via alternatives:

=== /usr/bin/js is a symlink... following it
lrwxrwxrwx 1 root root 20 Nov 21 08:54 /usr/bin/js -> /etc/alternatives/js
=== /etc/alternatives/js is a symlink... following it
lrwxrwxrwx 1 root root 14 Nov 21 08:54 /etc/alternatives/js -> /usr/bin/rhino
=== /usr/bin/rhino is owned by package: rhino ===

So calling either rhino or js will give you a JavaScript shell.

Edit (2014-06-30):

rhino is good to quickly test some javascript code in a file, but it is not an interactive shell, so it doesn't support GNU readline style of editing. For interactive work, you may prefer nodejs: on Ubuntu/debian sudo apt-get install nodejs. This should provide a more interactive js shell (invoke using the command js) where you can edit lines and recall history with the up/down arrow-keys. For a longer list of options, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells

share|improve this answer
add comment

In Chrome and Firefox, if you press F12 it brings up developer tools. Over there you could find a tab called console, where you could type and test JavaScript scripts. It has code completion and other features too.

share|improve this answer
4  
I think you didn't understand the question. I've asked about UNIX shell. But thanks for the willing to help anyway. –  J-unior Dec 9 '12 at 14:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.