我有一个从 bash 脚本调用的简短内联 python 脚本,我想让它处理一个多词变量(来自 $*
)。我希望这能正常工作:
#!/bin/bash
arg="A B C"
python -c "print '"$arg"'"
但它没有:
File "<string>", line 1
print 'A
^
SyntaxError: EOL while scanning string literal
为什么?
最佳答案
BASH 脚本错误。
#!/bin/bash
arg="A B C"
python -c "print '$arg'"
并输出
$ sh test.sh
A B C
请注意,要连接两个字符串变量,您不需要将它们放在字符串常量之外
关于python - 将多个参数从 bash 传递到 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29750203/