What is sh.js?

sh.js is a JavaScript library for Unix shell scripting working on node.js.

For example, to sort user names in /etc/passwd in a classical shell script, you could write:

cut -f1 -d: /etc/passwd | sort

With sh.js, the following statement would accomplish the same:

sh('cut -f1 -d: /etc/passwd')('sort');

Why try it?

You may find sh.js useful if:

What sh.js isn't


Run a command:

sh('echo hello');

Change the working directory and run a command in the new directory:

sh.cd('/').and('ls -l');

In a Git repository, put all authors with their email in a file:

sh('git log --pretty=format:"%aN %aE"')

Report the space availability of the root partition to the remote monitor.lan server:

sh('df')('awk \'{ if ($6 == "/") printf "%s", $5 }\'')
  .result(function(available) {
    sh('curl -d root="' + available + '" https://monitor.lan/disk_report');

For more examples, head to the tutorial.


As of now, sh.js still has some serious limitations: