How to tell bash to specifically escape a wildcard in a Python script

若如初见. 提交于 2019-12-23 05:27:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!