Portable Shell Commands for Node
Last updated 2 years ago by nfischer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install shx 
SYNC missed versions from official npm registry.


Travis AppVeyor Codecov npm version npm downloads

shx is a wrapper around ShellJS Unix commands, providing an easy solution for simple Unix-like, cross-platform commands in npm package scripts.

Difference Between ShellJS and shx

  • ShellJS: Good for writing long scripts, all in JS, running via NodeJS (e.g. node myScript.js).
  • shx: Good for writing one-off commands in npm package scripts (e.g. "clean": "shx rm -rf out/").


npm install shx --save-dev

This will allow using shx in your package.json scripts.


Command Line

If you'd like to use shx on the command line, install it globally with the -g flag. The following code can be run either a Unix or Windows command line:

$ shx pwd                       # ShellJS commands are supported automatically

$ shx ls                        # files are outputted one per line

$ shx rm *.txt                  # a cross-platform way to delete files!

$ shx ls

$ shx echo "Hi there!"
Hi there!

$ shx touch helloworld.txt

$ shx cp helloworld.txt foobar.txt

$ shx mkdir sub

$ shx ls

$ shx rm -r sub                 # options work as well

$ shx --silent ls fakeFileName  # silence error output

All commands internally call the ShellJS corresponding function, guaranteeing cross-platform compatibility.


ShellJS is good for writing long scripts. If you want to write bash-like, platform-independent scripts, we recommend you go with that.

However, shx is ideal for one-liners inside package.json:

  "scripts": {
    "clean": "shx rm -rf build dist && shx echo Done"

Unsupported Commands

Due to the differences in execution environments between ShellJS and shx (JS vs CLI) some commands are not supported:

Unsupported command Recommend workaround
shx cd Just use plain old cd (it's the same on windows too)
shx pushd Just use plain old pushd. Use forward slashes and double-quote the path. (e.g. pushd "../docs". This would fail on Windows without the quotes)
shx popd Just use plain old popd
shx dirs No workaround
shx set See below
shx exit Just use plain old exit
shx exec Instead of shx exec cmd, just use plain old cmd
shx ShellString No workaround (but why would you want this?)

Shx options

Shx allows you to modify its behavior by passing arguments. Here's a list of supported options:

set flag shell.config setting shx command Effect
-e config.fatal = true Not supported Exit upon first error
-v config.verbose = true shx --verbose cd foo Log the command as it's run
-f config.noglob = true shx --noglob cat '*.txt' Don't expand wildcards
N/A config.silent = true shx --silent cd noexist Don't show error output


Nate Fischer Ari Porad Levi Thomason
Nate Fischer Ari Porad Levi Thomason

Current Tags

  • 0.3.2                                ...           latest (2 years ago)

11 Versions

  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           4 years ago
  • 0.2.0 [deprecated]           ...           4 years ago
  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0 [deprecated]           ...           4 years ago
Maintainers (2)
Today 11
This Week 564
This Month 280
Last Day 141
Last Week 626
Last Month 3,058
Dependencies (3)
Dev Dependencies (16)
Dependents (132)

Copyright 2014 - 2016 © |