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

Implement shopt -s dotglob in OSH, glob() enhancements in YSH #610

Open
andychu opened this issue Feb 23, 2020 · 6 comments
Open

Implement shopt -s dotglob in OSH, glob() enhancements in YSH #610

andychu opened this issue Feb 23, 2020 · 6 comments

Comments

@andychu
Copy link
Contributor

andychu commented Feb 23, 2020

Related to #609 and #552

This should just be a libc flag change. Maybe wait until after translation is done?

@andychu
Copy link
Contributor Author

andychu commented Apr 8, 2020

There's a failing spec test for this in spec/glob.test.sh

$ test/spec.sh glob  -r 35 
glob.test.sh
case    line    dash    bash    mksh    ash     osh
 35     293     N-I     pass    N-I     N-I     FAIL    dotglob (bash option that dashglob is roughly consistent with)

                dash    bash    mksh    ash     osh
        pass    0       1       0       0       0
        N-I     1       0       1       1       0
        FAIL    0       0       0       0       1
        total   1       1       1       1       1

@andychu
Copy link
Contributor Author

andychu commented Jan 7, 2023

Demo

$ mkdir tmp
$ cd tmp
$ touch a b .bashrc
$ echo *
a b
$ shopt -s dotglob
$ echo *
a b .bashrc

@andychu
Copy link
Contributor Author

andychu commented Jan 7, 2023

man glob


       GLOB_PERIOD
              Allow a leading period to be matched by metacharacters.  By default, metacharacters can't match a leading period.

@jtb20
Copy link

jtb20 commented May 1, 2024

There's a good amount of horror to be seen here: https://superuser.com/questions/352289/bash-scripting-test-for-empty-directory! It's like a one-page summary of why ysh is needed all by itself.

I tried writing an "empty directory" test in ysh (0.21.0), but hit this issue:

func dir_empty (where) {
  cd $where {
    # shopt "dotglob" appears to be unimplemented. This'll do.
    var files=glob("*")++glob(".*")
    return (len(files) === 2)
  }
}

Not critical or anything, just a FYI.

@andychu
Copy link
Contributor Author

andychu commented May 1, 2024

OK interesting

osh-0.21.0$ = glob('*')
(List 0x7fb9cd964af0)   []
osh-0.21.0$ = glob('.*')
(List 0x7fb9cd964c30)   [".",".."]

I didn't know this was the behavior of glob

I think there are two different things here

  • bash-compatible shopt -s dotglob
  • optional args to glob() function in YSH

@andychu andychu changed the title Implement dotglob Implement shopt -s dotglob in OSH, glob() enhancements in YSH May 1, 2024
@jtb20
Copy link

jtb20 commented Jun 6, 2024

Test case:

dotglob.ysh.txt

HTH!

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

No branches or pull requests

2 participants