Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option not recognized #556

Closed
embrown30 opened this issue Nov 16, 2016 · 8 comments
Closed

Option not recognized #556

embrown30 opened this issue Nov 16, 2016 · 8 comments
Assignees

Comments

@embrown30
Copy link

Node version (or tell us if you're using electron or some other framework):

v6.4.0

ShellJS version (the most recent version/Github branch you see the bug on):

0.7.5

Operating system:

Mac OS Yosemite

Description of the bug:

Getting option not recognized when running ls -d

Example ShellJS command to reproduce the error:

var shell = require("shelljs");

shell.ls("-d", "./").forEach(function(dir){
    if(dir !== "node_modules"){
      console.log("dir: " + dir);
    }
  });
@nfischer
Copy link
Member

The option should be recognized. If not, this is a bug.

But why would you have code like that? I don't think it's going to do what you think it will...

@embrown30
Copy link
Author

I am trying to list the directories in the current directory and check the names of them.
Is there another way I can do this using another command?

@nfischer
Copy link
Member

Just use ls(). If you need hidden files, use ls('-a'). If you need only directories (no files), then use ls('-d', '*/')

@nfischer
Copy link
Member

Can't reproduce this on Linux, and I see no reason why it would only repro on Mac OS.

I'll try to repro on Mac OS tomorrow.

@nfischer nfischer assigned nfischer and freitagbr and unassigned nfischer Nov 16, 2016
@nfischer
Copy link
Member

@freitagbr can you reproduce this? I won't be able to look at this on my mac.

@embrown30
Copy link
Author

@nfischer I am able to use the command you sent. ls('-d', '*/')
Unsure why the current directory wouldn't be the second argument instead of the */.

For whatever reason, I am now unable to replicate what was happening before using ls('-d', './').
This was very strange how it just came and went.
Thanks for the help though!

@nfischer
Copy link
Member

@embrown30 from our docs:

-d: list directories themselves, not their contents

So if you use ls('-d', 'foo'), it means "Don't show me the contents of directory foo, just show me foo itself." Therefore, ls('-d', '.') means "show me . itself, not the stuff inside it." This always returns the array ['.'], which isn't very useful.

When in doubt, unix man pages can also help clarify ambiguities, since we strive for POSIX compliance where it makes sense. Hope this helps!

@freitagbr
Copy link
Contributor

I tested with ShellJS at 0.7.5 and node at 6.4.0, and I could not reproduce.

Maybe there was a globally installed version being used, instead of a locally installed version. For reference, the '-d' option was first introduced in version 0.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants