{"id":13441322,"url":"https://github.com/shelljs/shx","last_synced_at":"2025-05-11T13:58:36.542Z","repository":{"id":40693776,"uuid":"51710581","full_name":"shelljs/shx","owner":"shelljs","description":"Portable Shell Commands for Node","archived":false,"fork":false,"pushed_at":"2025-05-10T03:45:30.000Z","size":737,"stargazers_count":1773,"open_issues_count":20,"forks_count":48,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-05-11T13:58:31.422Z","etag":null,"topics":["bash","shelljs","unix"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shelljs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-02-14T19:53:03.000Z","updated_at":"2025-05-10T03:45:31.000Z","dependencies_parsed_at":"2024-06-01T21:09:09.086Z","dependency_job_id":"416ce55a-cf28-41d4-8810-f5ff4bcd3684","html_url":"https://github.com/shelljs/shx","commit_stats":{"total_commits":148,"total_committers":14,"mean_commits":"10.571428571428571","dds":0.6148648648648649,"last_synced_commit":"03c29642c2d284364d04ec243102ab7a7ef92622"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelljs%2Fshx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelljs%2Fshx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelljs%2Fshx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shelljs%2Fshx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shelljs","download_url":"https://codeload.github.com/shelljs/shx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253576262,"owners_count":21930169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","shelljs","unix"],"created_at":"2024-07-31T03:01:32.525Z","updated_at":"2025-05-11T13:58:36.471Z","avatar_url":"https://github.com/shelljs.png","language":"JavaScript","readme":"# Shx\n\n[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/shelljs/shx/main.yml?style=flat-square\u0026logo=github)](https://github.com/shelljs/shx/actions/workflows/main.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/shelljs/shx/main.svg?style=flat-square\u0026label=coverage)](https://codecov.io/gh/shelljs/shx)\n[![npm version](https://img.shields.io/npm/v/shx.svg?style=flat-square)](https://www.npmjs.com/package/shx)\n[![npm downloads](https://img.shields.io/npm/dm/shx.svg?style=flat-square)](https://www.npmjs.com/package/shx)\n\n`shx` is a wrapper around [ShellJS](https://github.com/shelljs/shelljs) Unix\ncommands, providing an easy solution for simple Unix-like, cross-platform\ncommands in npm package scripts.\n\n`shx` is proudly tested on every LTS node release since \u003c!-- start minVersion --\u003e`v18`\u003c!-- stop minVersion --\u003e!\n\n## Difference Between ShellJS and shx\n\n- **ShellJS:** Good for writing long scripts, all in JS, running via NodeJS (e.g. `node myScript.js`).\n- **shx:** Good for writing one-off commands in npm package scripts (e.g. `\"clean\": \"shx rm -rf out/\"`).\n\n## Install\n\n```shell\nnpm install shx --save-dev\n```\nThis will allow using `shx` in your `package.json` scripts.\n\n## Usage\n\n### Command Line\n\nIf you'd like to use `shx` on the command line, install it globally with the `-g` flag.\nThe following code can be run *either a Unix or Windows* command line:\n\n```Bash\n$ shx pwd                       # ShellJS commands are supported automatically\n/home/username/path/to/dir\n\n$ shx ls                        # files are outputted one per line\nfile.txt\nfile2.txt\n\n$ shx rm *.txt                  # a cross-platform way to delete files!\n\n$ shx ls\n\n$ shx echo \"Hi there!\"\nHi there!\n\n$ shx touch helloworld.txt\n\n$ shx cp helloworld.txt foobar.txt\n\n$ shx mkdir sub\n\n$ shx ls\nfoobar.txt\nhelloworld.txt\nsub\n\n$ shx rm -r sub                 # options work as well\n\n$ shx --silent ls fakeFileName  # silence error output\n\n$ shx --negate test -d dir      # Negate status code output (e.g., failed commands will now have status 0)\n```\n\nAll commands internally call the ShellJS corresponding function, guaranteeing\ncross-platform compatibility.\n\n### package.json\n\nShellJS is good for writing long scripts. If you want to write bash-like,\nplatform-independent scripts, we recommend you go with that.\n\nHowever, `shx` is ideal for one-liners inside `package.json`:\n\n```json\n{\n  \"scripts\": {\n    \"clean\": \"shx rm -rf \\\"build/**/*.js\\\" \\\"build/output\\\" \u0026\u0026 shx echo \\\"Done cleaning\\\"\"\n  }\n}\n```\n\nIt's safe to use `\u0026\u0026` and `||` operators in npm package scripts. These will be\ninterpreted by the operating system's shell (`sh` on Unix, `cmd.exe` on\nWindows). If you're using glob operators like `*` or `**`, then we recommend to\n**put these in double quotes**, which ensures that `shx` will expand the glob\nrather than the operating system shell.\n\n\u003e [!IMPORTANT]\n\u003e Windows treats single quotes (ex. `'some string'`) differently than double\n\u003e quotes.\n\u003e [We recommend](https://github.com/shelljs/shx/issues/165#issuecomment-563127983)\n\u003e wrapping your arguments in **escaped double quotes** so that your code is\n\u003e compatible cross platform (ex. `\"clean\": \"shx echo \\\"some string\\\"\"`).\n\n## Command reference\n\nShx exposes [most ShellJS\ncommands](https://github.com/shelljs/shelljs#command-reference). If a command is\nnot listed here, assume it's supported!\n\n### sed\n\nShx provides unix-like syntax on top of `shell.sed()`. So ShellJS code like:\n\n```js\nshell.sed('-i', /original string/g, 'replacement', 'filename.txt');\n```\n\nwould turn into the following Shx command:\n\n```sh\nshx sed -i \"s/original string/replacement/g\" filename.txt\n```\n\n**Note:** like unix `sed`, `shx sed` treats `/` as a special character, and\n[this must be\nescaped](https://github.com/shelljs/shx/issues/169#issuecomment-563013849) (as\n`\\/` in the shell, or `\\\\/` in `package.json`) if you intend to use this\ncharacter in either the regex or replacement string. Do **not** escape `/`\ncharacters in the file path.\n\n### Unsupported Commands\n\nAs mentioned above, most ShellJS commands are supported in `shx`. Due to the\ndifferences in execution environments between ShellJS and `shx` (JS vs CLI) the\nfollowing commands are not supported:\n\n| Unsupported command | Recommend workaround |\n| ------------------- | -------------------- |\n| `shx cd`            | Just use plain old `cd` (it's the same on windows too) |\n| `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) |\n| `shx popd`          | Just use plain old `popd` |\n| `shx dirs`          | No workaround |\n| `shx set`           | See below |\n| `shx exit`          | Just use plain old `exit` |\n| `shx exec`          | Instead of `shx exec cmd`, just use plain old `cmd` |\n| `shx ShellString`   | No workaround (but why would you want this?) |\n\n### Shx options\n\nShx allows you to modify its behavior by passing arguments. Here's a list of\nsupported options:\n\n| [`set`](https://github.com/shelljs/shelljs#setoptions) flag | [`shell.config`](https://github.com/shelljs/shelljs#configuration) setting | shx command | Effect |\n|:---:| --- | --- | --- |\n| `-e` | `config.fatal = true` | Not supported | Exit upon first error. |\n| `-v` | `config.verbose = true` | `shx --verbose cd foo` | Log the command as it's run. |\n| `-f` | `config.noglob = true` | `shx --noglob cat '*.txt'` | Don't expand wildcards. |\n| N/A | `config.silent = true` | `shx --silent cd noexist` | Don't show error output. |\n| N/A | N/A | `shx --negate test -d dir` | Runs the specified command but negates the exit status. Failed command = status 0, successful command = status 1. |\n| N/A | N/A | `shx --help` | Show help text. |\n| N/A | N/A | `shx --version` | Print the shx version. |\n\n## Team\n\n| [![Nate Fischer](https://avatars.githubusercontent.com/u/5801521?s=130)](https://github.com/nfischer) | [![Ari Porad](https://avatars1.githubusercontent.com/u/1817508?v=3\u0026s=130)](http://github.com/ariporad) | [![Levi Thomason](https://avatars1.githubusercontent.com/u/5067638?v=3\u0026s=130)](https://github.com/levithomason) |\n|:---:|:---:|:---:|\n| [Nate Fischer](https://github.com/nfischer) | [Ari Porad](http://github.com/ariporad) | [Levi Thomason](https://github.com/levithomason) |\n","funding_links":[],"categories":["HarmonyOS","JavaScript","Repository","bash","Cross-platform Utilities"],"sub_categories":["Windows Manager","Shell","Utility Packs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshelljs%2Fshx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshelljs%2Fshx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshelljs%2Fshx/lists"}