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

won't parse 'rm -f !(file.sh)' #9

Open
blurrymoi opened this issue Feb 28, 2016 · 4 comments
Open

won't parse 'rm -f !(file.sh)' #9

blurrymoi opened this issue Feb 28, 2016 · 4 comments

Comments

@blurrymoi
Copy link
Contributor

bashlex.errors.ParsingError: unexpected token '(' (position 7)

May be caused by the fact that '!' is interpreted as WORD instead of BANG.

@idank
Copy link
Owner

idank commented Mar 1, 2016

Huh. I recognize the ! for history expansion, but what does !(file.sh) do?

@blurrymoi
Copy link
Contributor Author

It's for pattern matching to exclude a single file so that it removes everything but the file.
http://wiki.bash-hackers.org/syntax/pattern#extended_pattern_language

@idank
Copy link
Owner

idank commented Mar 7, 2016

Oh, nice. Hmm, guess we have to debug bash again to see where we go wrong.

@samlikins
Copy link

In a Python interactive session with the following setup:

Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bashlex
>>> bashlex.parse('rm -f !(file.sh)')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.10/site-packages/bashlex/parser.py", line 610, in parse
    parts = [p.parse()]
  File "/home/user/.local/lib/python3.10/site-packages/bashlex/parser.py", line 691, in parse
    tree = theparser.parse(lexer=self.tok, context=self)
  File "/home/user/.local/lib/python3.10/site-packages/bashlex/yacc.py", line 537, in parse
    tok = self.errorfunc(errtoken)
  File "/home/user/.local/lib/python3.10/site-packages/bashlex/parser.py", line 548, in p_error
    raise errors.ParsingError('unexpected token %r' % p.value,
bashlex.errors.ParsingError: unexpected token '(' (position 7)

Error is still persisting, no additional revelations, just additional test data.

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