项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. # ShellJS - Unix shell commands for Node.js
  2. [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square)](https://gitter.im/shelljs/shelljs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  3. [![Travis](https://img.shields.io/travis/shelljs/shelljs/master.svg?style=flat-square&label=unix)](https://travis-ci.org/shelljs/shelljs)
  4. [![AppVeyor](https://img.shields.io/appveyor/ci/shelljs/shelljs/master.svg?style=flat-square&label=windows)](https://ci.appveyor.com/project/shelljs/shelljs/branch/master)
  5. [![Codecov](https://img.shields.io/codecov/c/github/shelljs/shelljs/master.svg?style=flat-square&label=coverage)](https://codecov.io/gh/shelljs/shelljs)
  6. [![npm version](https://img.shields.io/npm/v/shelljs.svg?style=flat-square)](https://www.npmjs.com/package/shelljs)
  7. [![npm downloads](https://img.shields.io/npm/dm/shelljs.svg?style=flat-square)](https://www.npmjs.com/package/shelljs)
  8. ShellJS is a portable **(Windows/Linux/OS X)** implementation of Unix shell
  9. commands on top of the Node.js API. You can use it to eliminate your shell
  10. script's dependency on Unix while still keeping its familiar and powerful
  11. commands. You can also install it globally so you can run it from outside Node
  12. projects - say goodbye to those gnarly Bash scripts!
  13. ShellJS is proudly tested on every node release since `v0.11`!
  14. The project is [unit-tested](http://travis-ci.org/shelljs/shelljs) and battle-tested in projects like:
  15. + [PDF.js](http://github.com/mozilla/pdf.js) - Firefox's next-gen PDF reader
  16. + [Firebug](http://getfirebug.com/) - Firefox's infamous debugger
  17. + [JSHint](http://jshint.com) & [ESLint](http://eslint.org/) - popular JavaScript linters
  18. + [Zepto](http://zeptojs.com) - jQuery-compatible JavaScript library for modern browsers
  19. + [Yeoman](http://yeoman.io/) - Web application stack and development tool
  20. + [Deployd.com](http://deployd.com) - Open source PaaS for quick API backend generation
  21. + And [many more](https://npmjs.org/browse/depended/shelljs).
  22. If you have feedback, suggestions, or need help, feel free to post in our [issue
  23. tracker](https://github.com/shelljs/shelljs/issues).
  24. Think ShellJS is cool? Check out some related projects in our [Wiki
  25. page](https://github.com/shelljs/shelljs/wiki)!
  26. Upgrading from an older version? Check out our [breaking
  27. changes](https://github.com/shelljs/shelljs/wiki/Breaking-Changes) page to see
  28. what changes to watch out for while upgrading.
  29. ## Command line use
  30. If you just want cross platform UNIX commands, checkout our new project
  31. [shelljs/shx](https://github.com/shelljs/shx), a utility to expose `shelljs` to
  32. the command line.
  33. For example:
  34. ```
  35. $ shx mkdir -p foo
  36. $ shx touch foo/bar.txt
  37. $ shx rm -rf foo
  38. ```
  39. ## A quick note about the docs
  40. For documentation on all the latest features, check out our
  41. [README](https://github.com/shelljs/shelljs). To read docs that are consistent
  42. with the latest release, check out [the npm
  43. page](https://www.npmjs.com/package/shelljs) or
  44. [shelljs.org](http://documentup.com/shelljs/shelljs).
  45. ## Installing
  46. Via npm:
  47. ```bash
  48. $ npm install [-g] shelljs
  49. ```
  50. ## Examples
  51. ```javascript
  52. var shell = require('shelljs');
  53. if (!shell.which('git')) {
  54. shell.echo('Sorry, this script requires git');
  55. shell.exit(1);
  56. }
  57. // Copy files to release dir
  58. shell.rm('-rf', 'out/Release');
  59. shell.cp('-R', 'stuff/', 'out/Release');
  60. // Replace macros in each .js file
  61. shell.cd('lib');
  62. shell.ls('*.js').forEach(function (file) {
  63. shell.sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
  64. shell.sed('-i', /^.*REMOVE_THIS_LINE.*$/, '', file);
  65. shell.sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, shell.cat('macro.js'), file);
  66. });
  67. shell.cd('..');
  68. // Run external tool synchronously
  69. if (shell.exec('git commit -am "Auto-commit"').code !== 0) {
  70. shell.echo('Error: Git commit failed');
  71. shell.exit(1);
  72. }
  73. ```
  74. ## Global vs. Local
  75. We no longer recommend using a global-import for ShellJS (i.e.
  76. `require('shelljs/global')`). While still supported for convenience, this
  77. pollutes the global namespace, and should therefore only be used with caution.
  78. Instead, we recommend a local import (standard for npm packages):
  79. ```javascript
  80. var shell = require('shelljs');
  81. shell.echo('hello world');
  82. ```
  83. <!-- DO NOT MODIFY BEYOND THIS POINT - IT'S AUTOMATICALLY GENERATED -->
  84. ## Command reference
  85. All commands run synchronously, unless otherwise stated.
  86. All commands accept standard bash globbing characters (`*`, `?`, etc.),
  87. compatible with the [node glob module](https://github.com/isaacs/node-glob).
  88. For less-commonly used commands and features, please check out our [wiki
  89. page](https://github.com/shelljs/shelljs/wiki).
  90. ### cat(file [, file ...])
  91. ### cat(file_array)
  92. Examples:
  93. ```javascript
  94. var str = cat('file*.txt');
  95. var str = cat('file1', 'file2');
  96. var str = cat(['file1', 'file2']); // same as above
  97. ```
  98. Returns a string containing the given file, or a concatenated string
  99. containing the files if more than one file is given (a new line character is
  100. introduced between each file).
  101. ### cd([dir])
  102. Changes to directory `dir` for the duration of the script. Changes to home
  103. directory if no argument is supplied.
  104. ### chmod([options,] octal_mode || octal_string, file)
  105. ### chmod([options,] symbolic_mode, file)
  106. Available options:
  107. + `-v`: output a diagnostic for every file processed
  108. + `-c`: like verbose but report only when a change is made
  109. + `-R`: change files and directories recursively
  110. Examples:
  111. ```javascript
  112. chmod(755, '/Users/brandon');
  113. chmod('755', '/Users/brandon'); // same as above
  114. chmod('u+x', '/Users/brandon');
  115. chmod('-R', 'a-w', '/Users/brandon');
  116. ```
  117. Alters the permissions of a file or directory by either specifying the
  118. absolute permissions in octal form or expressing the changes in symbols.
  119. This command tries to mimic the POSIX behavior as much as possible.
  120. Notable exceptions:
  121. + In symbolic modes, 'a-r' and '-r' are identical. No consideration is
  122. given to the umask.
  123. + There is no "quiet" option since default behavior is to run silent.
  124. ### cp([options,] source [, source ...], dest)
  125. ### cp([options,] source_array, dest)
  126. Available options:
  127. + `-f`: force (default behavior)
  128. + `-n`: no-clobber
  129. + `-u`: only copy if source is newer than dest
  130. + `-r`, `-R`: recursive
  131. + `-L`: follow symlinks
  132. + `-P`: don't follow symlinks
  133. Examples:
  134. ```javascript
  135. cp('file1', 'dir1');
  136. cp('-R', 'path/to/dir/', '~/newCopy/');
  137. cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp');
  138. cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above
  139. ```
  140. Copies files.
  141. ### pushd([options,] [dir | '-N' | '+N'])
  142. Available options:
  143. + `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
  144. Arguments:
  145. + `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`.
  146. + `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
  147. + `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
  148. Examples:
  149. ```javascript
  150. // process.cwd() === '/usr'
  151. pushd('/etc'); // Returns /etc /usr
  152. pushd('+1'); // Returns /usr /etc
  153. ```
  154. Save the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
  155. ### popd([options,] ['-N' | '+N'])
  156. Available options:
  157. + `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.
  158. Arguments:
  159. + `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
  160. + `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
  161. Examples:
  162. ```javascript
  163. echo(process.cwd()); // '/usr'
  164. pushd('/etc'); // '/etc /usr'
  165. echo(process.cwd()); // '/etc'
  166. popd(); // '/usr'
  167. echo(process.cwd()); // '/usr'
  168. ```
  169. When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
  170. ### dirs([options | '+N' | '-N'])
  171. Available options:
  172. + `-c`: Clears the directory stack by deleting all of the elements.
  173. Arguments:
  174. + `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero.
  175. + `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero.
  176. Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.
  177. See also: pushd, popd
  178. ### echo([options,] string [, string ...])
  179. Available options:
  180. + `-e`: interpret backslash escapes (default)
  181. Examples:
  182. ```javascript
  183. echo('hello world');
  184. var str = echo('hello world');
  185. ```
  186. Prints string to stdout, and returns string with additional utility methods
  187. like `.to()`.
  188. ### exec(command [, options] [, callback])
  189. Available options (all `false` by default):
  190. + `async`: Asynchronous execution. If a callback is provided, it will be set to
  191. `true`, regardless of the passed value.
  192. + `silent`: Do not echo program output to console.
  193. + and any option available to Node.js's
  194. [child_process.exec()](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
  195. Examples:
  196. ```javascript
  197. var version = exec('node --version', {silent:true}).stdout;
  198. var child = exec('some_long_running_process', {async:true});
  199. child.stdout.on('data', function(data) {
  200. /* ... do something with data ... */
  201. });
  202. exec('some_long_running_process', function(code, stdout, stderr) {
  203. console.log('Exit code:', code);
  204. console.log('Program output:', stdout);
  205. console.log('Program stderr:', stderr);
  206. });
  207. ```
  208. Executes the given `command` _synchronously_, unless otherwise specified. When in synchronous
  209. mode, this returns a ShellString (compatible with ShellJS v0.6.x, which returns an object
  210. of the form `{ code:..., stdout:... , stderr:... }`). Otherwise, this returns the child process
  211. object, and the `callback` gets the arguments `(code, stdout, stderr)`.
  212. Not seeing the behavior you want? `exec()` runs everything through `sh`
  213. by default (or `cmd.exe` on Windows), which differs from `bash`. If you
  214. need bash-specific behavior, try out the `{shell: 'path/to/bash'}` option.
  215. **Note:** For long-lived processes, it's best to run `exec()` asynchronously as
  216. the current synchronous implementation uses a lot of CPU. This should be getting
  217. fixed soon.
  218. ### find(path [, path ...])
  219. ### find(path_array)
  220. Examples:
  221. ```javascript
  222. find('src', 'lib');
  223. find(['src', 'lib']); // same as above
  224. find('.').filter(function(file) { return file.match(/\.js$/); });
  225. ```
  226. Returns array of all files (however deep) in the given paths.
  227. The main difference from `ls('-R', path)` is that the resulting file names
  228. include the base directories, e.g. `lib/resources/file1` instead of just `file1`.
  229. ### grep([options,] regex_filter, file [, file ...])
  230. ### grep([options,] regex_filter, file_array)
  231. Available options:
  232. + `-v`: Inverse the sense of the regex and print the lines not matching the criteria.
  233. + `-l`: Print only filenames of matching files
  234. Examples:
  235. ```javascript
  236. grep('-v', 'GLOBAL_VARIABLE', '*.js');
  237. grep('GLOBAL_VARIABLE', '*.js');
  238. ```
  239. Reads input string from given files and returns a string containing all lines of the
  240. file that match the given `regex_filter`.
  241. ### head([{'-n': \<num\>},] file [, file ...])
  242. ### head([{'-n': \<num\>},] file_array)
  243. Available options:
  244. + `-n <num>`: Show the first `<num>` lines of the files
  245. Examples:
  246. ```javascript
  247. var str = head({'-n': 1}, 'file*.txt');
  248. var str = head('file1', 'file2');
  249. var str = head(['file1', 'file2']); // same as above
  250. ```
  251. Read the start of a file.
  252. ### ln([options,] source, dest)
  253. Available options:
  254. + `-s`: symlink
  255. + `-f`: force
  256. Examples:
  257. ```javascript
  258. ln('file', 'newlink');
  259. ln('-sf', 'file', 'existing');
  260. ```
  261. Links source to dest. Use -f to force the link, should dest already exist.
  262. ### ls([options,] [path, ...])
  263. ### ls([options,] path_array)
  264. Available options:
  265. + `-R`: recursive
  266. + `-A`: all files (include files beginning with `.`, except for `.` and `..`)
  267. + `-L`: follow symlinks
  268. + `-d`: list directories themselves, not their contents
  269. + `-l`: list objects representing each file, each with fields containing `ls
  270. -l` output fields. See
  271. [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats)
  272. for more info
  273. Examples:
  274. ```javascript
  275. ls('projs/*.js');
  276. ls('-R', '/users/me', '/tmp');
  277. ls('-R', ['/users/me', '/tmp']); // same as above
  278. ls('-l', 'file.txt'); // { name: 'file.txt', mode: 33188, nlink: 1, ...}
  279. ```
  280. Returns array of files in the given path, or in current directory if no path provided.
  281. ### mkdir([options,] dir [, dir ...])
  282. ### mkdir([options,] dir_array)
  283. Available options:
  284. + `-p`: full path (will create intermediate dirs if necessary)
  285. Examples:
  286. ```javascript
  287. mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g');
  288. mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above
  289. ```
  290. Creates directories.
  291. ### mv([options ,] source [, source ...], dest')
  292. ### mv([options ,] source_array, dest')
  293. Available options:
  294. + `-f`: force (default behavior)
  295. + `-n`: no-clobber
  296. Examples:
  297. ```javascript
  298. mv('-n', 'file', 'dir/');
  299. mv('file1', 'file2', 'dir/');
  300. mv(['file1', 'file2'], 'dir/'); // same as above
  301. ```
  302. Moves files.
  303. ### pwd()
  304. Returns the current directory.
  305. ### rm([options,] file [, file ...])
  306. ### rm([options,] file_array)
  307. Available options:
  308. + `-f`: force
  309. + `-r, -R`: recursive
  310. Examples:
  311. ```javascript
  312. rm('-rf', '/tmp/*');
  313. rm('some_file.txt', 'another_file.txt');
  314. rm(['some_file.txt', 'another_file.txt']); // same as above
  315. ```
  316. Removes files.
  317. ### sed([options,] search_regex, replacement, file [, file ...])
  318. ### sed([options,] search_regex, replacement, file_array)
  319. Available options:
  320. + `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_
  321. Examples:
  322. ```javascript
  323. sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');
  324. sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
  325. ```
  326. Reads an input string from `files` and performs a JavaScript `replace()` on the input
  327. using the given search regex and replacement string or function. Returns the new string after replacement.
  328. Note:
  329. Like unix `sed`, ShellJS `sed` supports capture groups. Capture groups are specified
  330. using the `$n` syntax:
  331. ```javascript
  332. sed(/(\w+)\s(\w+)/, '$2, $1', 'file.txt');
  333. ```
  334. ### set(options)
  335. Available options:
  336. + `+/-e`: exit upon error (`config.fatal`)
  337. + `+/-v`: verbose: show all commands (`config.verbose`)
  338. + `+/-f`: disable filename expansion (globbing)
  339. Examples:
  340. ```javascript
  341. set('-e'); // exit upon first error
  342. set('+e'); // this undoes a "set('-e')"
  343. ```
  344. Sets global configuration variables
  345. ### sort([options,] file [, file ...])
  346. ### sort([options,] file_array)
  347. Available options:
  348. + `-r`: Reverse the result of comparisons
  349. + `-n`: Compare according to numerical value
  350. Examples:
  351. ```javascript
  352. sort('foo.txt', 'bar.txt');
  353. sort('-r', 'foo.txt');
  354. ```
  355. Return the contents of the files, sorted line-by-line. Sorting multiple
  356. files mixes their content, just like unix sort does.
  357. ### tail([{'-n': \<num\>},] file [, file ...])
  358. ### tail([{'-n': \<num\>},] file_array)
  359. Available options:
  360. + `-n <num>`: Show the last `<num>` lines of the files
  361. Examples:
  362. ```javascript
  363. var str = tail({'-n': 1}, 'file*.txt');
  364. var str = tail('file1', 'file2');
  365. var str = tail(['file1', 'file2']); // same as above
  366. ```
  367. Read the end of a file.
  368. ### tempdir()
  369. Examples:
  370. ```javascript
  371. var tmp = tempdir(); // "/tmp" for most *nix platforms
  372. ```
  373. Searches and returns string containing a writeable, platform-dependent temporary directory.
  374. Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
  375. ### test(expression)
  376. Available expression primaries:
  377. + `'-b', 'path'`: true if path is a block device
  378. + `'-c', 'path'`: true if path is a character device
  379. + `'-d', 'path'`: true if path is a directory
  380. + `'-e', 'path'`: true if path exists
  381. + `'-f', 'path'`: true if path is a regular file
  382. + `'-L', 'path'`: true if path is a symbolic link
  383. + `'-p', 'path'`: true if path is a pipe (FIFO)
  384. + `'-S', 'path'`: true if path is a socket
  385. Examples:
  386. ```javascript
  387. if (test('-d', path)) { /* do something with dir */ };
  388. if (!test('-f', path)) continue; // skip if it's a regular file
  389. ```
  390. Evaluates expression using the available primaries and returns corresponding value.
  391. ### ShellString.prototype.to(file)
  392. Examples:
  393. ```javascript
  394. cat('input.txt').to('output.txt');
  395. ```
  396. Analogous to the redirection operator `>` in Unix, but works with
  397. ShellStrings (such as those returned by `cat`, `grep`, etc). _Like Unix
  398. redirections, `to()` will overwrite any existing file!_
  399. ### ShellString.prototype.toEnd(file)
  400. Examples:
  401. ```javascript
  402. cat('input.txt').toEnd('output.txt');
  403. ```
  404. Analogous to the redirect-and-append operator `>>` in Unix, but works with
  405. ShellStrings (such as those returned by `cat`, `grep`, etc).
  406. ### touch([options,] file [, file ...])
  407. ### touch([options,] file_array)
  408. Available options:
  409. + `-a`: Change only the access time
  410. + `-c`: Do not create any files
  411. + `-m`: Change only the modification time
  412. + `-d DATE`: Parse DATE and use it instead of current time
  413. + `-r FILE`: Use FILE's times instead of current time
  414. Examples:
  415. ```javascript
  416. touch('source.js');
  417. touch('-c', '/path/to/some/dir/source.js');
  418. touch({ '-r': FILE }, '/path/to/some/dir/source.js');
  419. ```
  420. Update the access and modification times of each FILE to the current time.
  421. A FILE argument that does not exist is created empty, unless -c is supplied.
  422. This is a partial implementation of *[touch(1)](http://linux.die.net/man/1/touch)*.
  423. ### uniq([options,] [input, [output]])
  424. Available options:
  425. + `-i`: Ignore case while comparing
  426. + `-c`: Prefix lines by the number of occurrences
  427. + `-d`: Only print duplicate lines, one for each group of identical lines
  428. Examples:
  429. ```javascript
  430. uniq('foo.txt');
  431. uniq('-i', 'foo.txt');
  432. uniq('-cd', 'foo.txt', 'bar.txt');
  433. ```
  434. Filter adjacent matching lines from input
  435. ### which(command)
  436. Examples:
  437. ```javascript
  438. var nodeExec = which('node');
  439. ```
  440. Searches for `command` in the system's PATH. On Windows, this uses the
  441. `PATHEXT` variable to append the extension if it's not already executable.
  442. Returns string containing the absolute path to the command.
  443. ### exit(code)
  444. Exits the current process with the given exit code.
  445. ### error()
  446. Tests if error occurred in the last command. Returns a truthy value if an
  447. error returned and a falsy value otherwise.
  448. **Note**: do not rely on the
  449. return value to be an error message. If you need the last error message, use
  450. the `.stderr` attribute from the last command's return value instead.
  451. ### ShellString(str)
  452. Examples:
  453. ```javascript
  454. var foo = ShellString('hello world');
  455. ```
  456. Turns a regular string into a string-like object similar to what each
  457. command returns. This has special methods, like `.to()` and `.toEnd()`
  458. ### env['VAR_NAME']
  459. Object containing environment variables (both getter and setter). Shortcut
  460. to process.env.
  461. ### Pipes
  462. Examples:
  463. ```javascript
  464. grep('foo', 'file1.txt', 'file2.txt').sed(/o/g, 'a').to('output.txt');
  465. echo('files with o\'s in the name:\n' + ls().grep('o'));
  466. cat('test.js').exec('node'); // pipe to exec() call
  467. ```
  468. Commands can send their output to another command in a pipe-like fashion.
  469. `sed`, `grep`, `cat`, `exec`, `to`, and `toEnd` can appear on the right-hand
  470. side of a pipe. Pipes can be chained.
  471. ## Configuration
  472. ### config.silent
  473. Example:
  474. ```javascript
  475. var sh = require('shelljs');
  476. var silentState = sh.config.silent; // save old silent state
  477. sh.config.silent = true;
  478. /* ... */
  479. sh.config.silent = silentState; // restore old silent state
  480. ```
  481. Suppresses all command output if `true`, except for `echo()` calls.
  482. Default is `false`.
  483. ### config.fatal
  484. Example:
  485. ```javascript
  486. require('shelljs/global');
  487. config.fatal = true; // or set('-e');
  488. cp('this_file_does_not_exist', '/dev/null'); // throws Error here
  489. /* more commands... */
  490. ```
  491. If `true` the script will throw a Javascript error when any shell.js
  492. command encounters an error. Default is `false`. This is analogous to
  493. Bash's `set -e`
  494. ### config.verbose
  495. Example:
  496. ```javascript
  497. config.verbose = true; // or set('-v');
  498. cd('dir/');
  499. rm('-rf', 'foo.txt', 'bar.txt');
  500. exec('echo hello');
  501. ```
  502. Will print each command as follows:
  503. ```
  504. cd dir/
  505. rm -rf foo.txt bar.txt
  506. exec echo hello
  507. ```
  508. ### config.globOptions
  509. Example:
  510. ```javascript
  511. config.globOptions = {nodir: true};
  512. ```
  513. Use this value for calls to `glob.sync()` instead of the default options.
  514. ### config.reset()
  515. Example:
  516. ```javascript
  517. var shell = require('shelljs');
  518. // Make changes to shell.config, and do stuff...
  519. /* ... */
  520. shell.config.reset(); // reset to original state
  521. // Do more stuff, but with original settings
  522. /* ... */
  523. ```
  524. Reset shell.config to the defaults:
  525. ```javascript
  526. {
  527. fatal: false,
  528. globOptions: {},
  529. maxdepth: 255,
  530. noglob: false,
  531. silent: false,
  532. verbose: false,
  533. }
  534. ```
  535. ## Team
  536. | [![Nate Fischer](https://avatars.githubusercontent.com/u/5801521?s=130)](https://github.com/nfischer) | [![Brandon Freitag](https://avatars1.githubusercontent.com/u/5988055?v=3&s=130)](http://github.com/freitagbr) |
  537. |:---:|:---:|
  538. | [Nate Fischer](https://github.com/nfischer) | [Brandon Freitag](http://github.com/freitagbr) |