faqs.md
This file
Path
docs/faqs.md
39 lines · 1.1 KiB · Markdown
Last changed by
Make faqs section. Add the first question about windows shell expansion. (#2927)Rowlando13before adoption9ce34f2
History of this fileTake it
faqs.md
Frequently Asked Questions
:depth: 2
:local: true
General
Shell Variable Expansion On Windows
I have a simple Click app :
import click
@click.command()
@click.argument('message')
def main(message: str):
click.echo(message)
if __name__ == '__main__':
main()
When you pass an environment variable in the argument, it expands it:
> Desktop python foo.py '$M0/.viola/2025-01-25-17-20-23-307878'
> M:/home/ramrachum/.viola/2025-01-25-17-20-23-307878
>
Note that I used single quotes above, so my shell is not expanding the environment variable, Click does. How do I get Click to not expand it?
Answer
If you don't want Click to emulate (as best it can) unix expansion on Windows, pass windows_expand_args=False when calling the CLI. Windows command line doesn't do any *, ~, or $ENV expansion. It also doesn't distinguish between double quotes and single quotes (where the later means "don't expand here"). Click emulates the expansion so that the app behaves similarly on both platforms, but doesn't receive information about what quotes were used.