python中如何向shell脚本传递带空格的参数

假设 python 中向 shell传递参数

1. testArguments = "heihei"

os.system('./test.sh   {}'.format(testArguments)); 无问题

2. 

testArguments = "hei     hei"

os.system('./test.sh   {}'.format(testArguments)); 

则 test.sh 接收到的第一个参数是 hei ,而不是 "hei   hei"

怎么修正呢?

给{}带上引号即可

os.system('./test.sh  " {}"'.format(testArguments)); 

原文地址:https://www.cnblogs.com/yyzyxy/p/10948091.html