简体   繁体   English

可执行python文件sys不接受'('字符

[英]executable python file sys not accepting '(' character

I am trying to write a python file that takes command line input and performs some actions. 我正在尝试编写一个Python文件,该文件接受命令行输入并执行一些操作。 The input will consist of az, [, ], ( and ). 输入将由az,[,],(和)组成。 I made the following program just to check that I could keep going: 我制作了以下程序只是为了检查我是否可以继续前进:

#!/usr/bin/env python
import sys

print str(sys.argv)

I did chmod +x program and tried calling ./program qwerty (abc) [hi] and it returned: 我做了chmod +x program并尝试调用./program qwerty (abc) [hi] ,它返回:

-bash: syntax error near unexpected token `(' -bash:意外令牌'('附近的语法错误

Is there any way of changing the program so that it accepted parentheses in arguments? 有什么方法可以更改程序 ,使其接受参数中的括号吗?

Note: I have also tried placing square brackets before parentheses and it returns the same error. 注意:我也尝试将方括号放在括号前,它会返回相同的错误。

There's nothing the script can do about shell syntax when invoking the script. 调用脚本时,脚本对外壳语法无能为力。 The shell parses the command line first. Shell首先解析命令行。 You have to escape or quote characters that have special meaning in the shell (which includes most punctuation characters): 您必须转义或引用外壳中具有特殊含义的字符(包括大多数标点符号):

./program qwerty \(abc\) '[hi]'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM