如何告诉bash在Python脚本中专门转义通配符 [英] How to tell bash to specifically escape a wildcard in a Python script
问题描述
我有一个剧本.它带有参数,但是当它接收到字符串" *
"时,我希望将其自动填充为列表变量中的匹配字符串.
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"
不这样做将导致bash将其扩展到工作目录中的文件,然后将其传递给我的脚本.
Not doing so would result in bash expanding it to a file in the working directory, then passing it to my script.
告诉bash不要自动扩展星号并将其传递给我的脚本的要求是什么.也许是安装脚本?
What is required to tell bash to not automatically expand the asterisk and just pass it to my script. Maybe an install script?
推荐答案
set -o noglob
将防止bash扩展 *
.
使用 set + o noglob
这篇关于如何告诉bash在Python脚本中专门转义通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!