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

Regexes in grep #67

Open
Bost opened this issue Jan 10, 2020 · 9 comments
Open

Regexes in grep #67

Bost opened this issue Jan 10, 2020 · 9 comments

Comments

@Bost
Copy link

Bost commented Jan 10, 2020

Hi, I have a problem using regexes in grep. Following examples don't terminate when started from rash-repl:

grep -i "computer.*store"  purchases.csv
grep -i "computer.*?store" purchases.csv
grep -i "computer.+?store" purchases.csv

My purchases.csv contains:

"amount","where"
"100"   ,"supermarket"
"200"   ,"computer store X"
"300"   ,"petrol station"
"400"   ,"computer store Y"
"500"   ,"retail store"

I tried to look at the source code, but I'm not sure:

  • Is there a bug in the current run-pipeline implementation (or somewhere else)?
  • Or is there anything, some expansions which are not implemented yet?

Could you shed some light on this spot please? Thanks

@willghatch
Copy link
Owner

willghatch commented Jan 10, 2020 via email

@kisaragi-hiu
Copy link

For reference, fish returns error if a glob doesn't match anything, instead of silently discarding the argument (the case here) or becoming a literal string (bash).

u0_a135@localhost ~> ls does*not*match
fish: No matches for wildcard 'does*not*match'. See `help expand`.
ls does*not*match
   ^
u0_a135@localhost ~>

This is neither confusing or surprising, and is the best behavior in my opinion.

@capfredf
Copy link

capfredf commented Jan 11, 2020

I think auto-globbing might need to be turned off when * or ? appears in a regular expression

@willghatch
Copy link
Owner

@kisaragi-hiu Erroring when a glob matches nothing is probably the best behavior. The docs promise some backwards compatability at this point, so maybe that will have to be an option when creating a custom unix pipe. But I'll definitely put in an option for that, and make it the default behavior of globs in any Rash2 and other Rash derivatives that I plan on making.

@capfredf The problem is that the shell doesn't know that the string is meant as a regexp, only grep does. Another program might process the same string differently, and the shell can't know (without code specific to each command) how to treat arguments to different programs. You can make custom code for any command by making an alias, but I don't think it would be a good idea to include a bunch of command-specific code in the core of Rash. Honestly I think requiring explicit globs is probably a better design, but for some reason I decided to make the default unix pipe's behavior closer to more traditional shells in this area.

@capfredf
Copy link

capfredf commented Jan 21, 2020

@willghatch Thanks for your explanation.
is it possible to automatically turn off glob expansion when * or ? is surrounded by double quotes? Just like how they behave in bash or zsh?

In zsh:

➜  wonks.github.io git:(master) ls *.yml
_config.yml
➜  wonks.github.io git:(master) ls "*.yml"
ls: *.yml: No such file or directory

In rash

> ls *.yml
/Users/capfredf/code/wonks.github.io/_config.yml
14:09 [master] /Users/capfredf/code/wonks.github.io/
> ls "*.yml"
/Users/capfredf/code/wonks.github.io/_config.yml
14:09 [master] /Users/capfredf/code/wonks.github.io/

i.e, treat "" as '. Maybe it is not a design choice but I think it is more in line with users' expectation when transitioning from zsh or bash to rash

@capfredf
Copy link

just out of curiosity, is the repo of Rash 2 open to public access?

@Bost
Copy link
Author

Bost commented Mar 1, 2021

PING... Any news regarding the Rash2?

@willghatch
Copy link
Owner

willghatch commented Mar 1, 2021 via email

@Bost
Copy link
Author

Bost commented Mar 1, 2021

No rush :) just a little bit of pressure from over here :) Anyway thanks for a prompt answer.

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

4 participants