This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: sys.argv incorrectly parses command lines with args in environment variables.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Jason Williams, gvanrossum
Priority: normal Keywords:

Created on 2021-01-20 20:07 by Jason Williams, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit Jason Williams, 2021-01-20 20:07
private_key.pem Jason Williams, 2021-01-20 20:10
Messages (2)
msg385366 - (view) Author: Jason Williams (Jason Williams) Date: 2021-01-20 20:07
Passing arguments to a Python script using an environment variable like:

export en_auth="--arg1 test --arg2 \"$(<private_key.pem)\""
./ $en_auth

Incorrectly treats the value of arg2 as another argument rather than a value because the file value being inserted starts with "--":

sys.argv parses it as:
['--arg1', 'test', '--arg2', '"-----BEGIN', 'EC', 'PARAMETERS-----', 'BggqhkjOPQMBBw==', '-----END', 'EC', 'PARAMETERS-----"']

If the arguments are provided directly to the script it parses correctly:
./ --arg1 test --arg2 "$(<private_key.pem)"

['--base-api-url', 'test', '--provisioning-device-private-key', '-----BEGIN EC PARAMETERS-----']

This looks like two bugs...sys.argv is splitting the value incorrectly because its ignoring the quoting, and argparse is treating values that start with -- as arguments.
msg385368 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-20 20:49
That looks like you need to learn more about the shell. It is not a Python bug.
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87149
2021-01-20 20:49:52gvanrossumsetstatus: open -> closed

nosy: + gvanrossum
messages: + msg385368

resolution: not a bug
stage: resolved
2021-01-20 20:10:48Jason Williamssetfiles: + private_key.pem
2021-01-20 20:07:37Jason Williamssettype: behavior
components: + Library (Lib)
2021-01-20 20:07:16Jason Williamscreate