andrewchambers / janet-sh

Shorthand shell like functions for janet.
84 stars 7 forks source link

sh/glob produces unexpected results if directory is empty #6

Closed subsetpark closed 3 years ago

subsetpark commented 3 years ago

I have two directories, full and empty. full has a file in it; empty does not. I would expect that a wildcard search inside of full would return an array with one entry, and that a search inside of empty would return an empty array.

Here's a session:

Janet 1.12.2-5df8ac5 linux/x64 - '(doc)' for help
repl:1:> (import sh)
nil
repl:2:> (sh/glob "full/*")
@["full/foo"]
repl:3:> (sh/glob "empty/*")
@["empty/*"]
repl:4:> 

Instead of returning an empty array, a glob wildcard inside of an empty directory returns a string of the wildcard itself.

andrewchambers commented 3 years ago

This is consistent with shells, if you don't want that you pass the :x flag, see the docstring i guess.

subsetpark commented 3 years ago

Interesting, thanks for the pointer. When you say consistent, do you mean that returning the glob is equivalent to an error message like ls: cannot access 'src/*foo': No such file or directory? Or is there some shell convention that actually prints a wildcard if it doesn't match anything?

andrewchambers commented 3 years ago

shell passes the original string to the program if there was no glob match, that error message you posted comes from ls.