问题
I have a script. It takes arguments, but I would like it, when it receives the string "*
", to autocomplete it to a matching string in a list variable.
Unfortunately, this is impossible without the user escaping the wildcard using a backslash to escape the asterisk:
foo.py ba\* # Will expand to "bar"
Not doing so would result in bash expanding it to a file in the working directory, then passing it to my script.
What is required to tell bash to not automatically expand the asterisk and just pass it to my script. Maybe an install script?
回答1:
set -o noglob
will prevent bash from expanding the *
.
Remove with set +o noglob
回答2:
Simply call it like so to escape in bash:
foo.py 'ba*'
来源:https://stackoverflow.com/questions/15812682/how-to-tell-bash-to-specifically-escape-a-wildcard-in-a-python-script