shelljs / shx

Portable Shell Commands for Node
MIT License
1.73k stars 45 forks source link

shx grep -v adds extra newline #163

Open backspaces opened 5 years ago

backspaces commented 5 years ago

Certain uses of grep appear to add extra newlines.

Ex: Try something like this:

shx ls '~/Music/iTunes' | shx grep 'iTunes'

It acts as expected, producing strings with a single \n for each line.

But

shx ls '~/Music/iTunes' | shx grep '-v' 'iTunes'

appears to add a second newline at the end of the set of strings.

This can be explicitly seen in node:

var sh = require('shelljs')
// terminates with a single newline
sh.ls('~/Music/iTunes').grep('iTunes')
// terminates with two newlines
sh.ls('~/Music/iTunes').grep('-v', 'iTunes')
nfischer commented 5 years ago

Yeah, I can repro. Seems like a bug in grep() rather than ls().

shx ls | shx grep -v 'foo' # bug
shx ls | grep -v 'foo'     # no bug
ls | shx grep -v 'foo'     # bug
ls | grep -v 'foo'         # no bug

PRs are welcome for https://github.com/shelljs/shelljs (it seems the bug is there, rather than in this project).