Get unexpanded argument from bash command line

Viewed 316

When passing a glob expression as an argument to a script from the bash command line, it gets expanded, and the files matching it are unpacked into sys.argv:

# stuff.py
import sys

print(sys.argv)
host:~$ python stuff.py a*
['stuff.py', 'a1', 'a2', 'a3']

I would like to get these files in an container, as a single element of sys.argv:

host:~$ python stuff.py a*
['stuff.py', ['a1', 'a2', 'a3']]

I know that putting the glob expression in quotes and using the glob module solves the problem:

import sys
import glob

print(glob.glob(sys.argv[1]))
host:~$ python stuff.py "a*"
['a1', 'a2', 'a3']

However, this requires to add quotes around the arguments, so tab-completion cannot be used directly.

Is it possible to prevent the command line arguments from being expanded?

1 Answers
Related