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

Quoted text is handled as option #480

Closed
nerg4l opened this issue Jun 19, 2020 · 2 comments
Closed

Quoted text is handled as option #480

nerg4l opened this issue Jun 19, 2020 · 2 comments

Comments

@nerg4l
Copy link

nerg4l commented Jun 19, 2020

Given the following doc:

Usage:
  naval_fate.py a <name>...
  naval_fate.py b -- <name>...

The following commands are faling regardless of single-quotes (') or double-quotes ("):

a "-a"
a "--a"
a '-a'
a '--a'

And these are correct regardless of the quotes and the number of dashes:

a "-"
a " -a"
a -- "-a" # parsed as two parameter
a -- "-b" # parsed as one parameter

In the docs there is a section about double dash -- which can be used to "separate options and positional arguments". I can use that to avoid this as you can see the second usage pattern of the example.

I don't think it is intended behaviour but I can be wrong.

According to https://www.gnu.org/software/bash/manual/bash.html#Quoting

Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes.

Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’.

A could only find this in the IEEE Std 1003.1-2017 specs https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02

Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to preserve the literal meaning of the special characters in the next paragraph, prevent reserved words from being recognized as such, and prevent parameter expansion and command substitution within here-document processing [...]

@TylerTemp
Copy link

This is likely to be an bash (or whatever cli tty you are using)'s arguments feature.

a simple python example:

import sys
print(sys.argv[1:])

a simple bash example:

echo $@

Both scripts will parse quote and will not pass quote to the script argv.

Thus,

a "-a"  # result: a -a
a "--a"  # result: a --a
a '-a'  # result: a -a
a '--a'  # result: a --a

@nerg4l nerg4l closed this as completed Aug 26, 2020
@pilattebe
Copy link

I have a pending pull request to fix this since 2018 here

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