Python argparse - arguments strip off when bash special character is passed as argument
<p>I writing CLI tool using argparse.</p>

<p>Below is my code snippet:</p>

<pre><code>parser.ArgumentParser()
parser.add_argument('--username')
parser.add_argument('--password')
args = parser.parse_args()
print(args.password)
</code></pre>

<p>I run the script on my Mac:</p>

<p><code>&gt;&gt;&gt; prog.py --username xyz --password abc$xyz</code></p>

<p>Output:</p>

<p><code>&gt;&gt;&gt; abc</code></p>

<p>I know it's bash shell that interprets '$xyz' as a bash variable and tries to substitute '$xyz'</p>

<p>Is there are way I can get around this without enclosing the password in quotes? </p>

<p>You can put a backslash in front of the <code>$</code>: <code>prog.py --username xyz --password abc\$xyz</code>.</p>

<p>Otherwise, no. You correctly observed that it is bash that is doing this so, by the time Python/argparse receives the command, there is nothing that can be done.</p>

python bash argparse