假设我们在 python 中有一个字符串变量,我们想将它与 shell 脚本中的其他字符串连接起来。例如,假设变量是基地址。我们想要对基目录中的文件运行命令,例如 rm,如下所示:
base_address = "<addr>"
!echo "${base_address}/file_name.xml"
但它在这里不起作用(与 bash 相比)。 “$base_address/file_name.xml”
也是同样的情况。解决办法是什么?
最佳答案
要在 shell 脚本中联系字符串变量,您需要将其放在字符串的其他部分旁边,如下所示:
base_address = "<addr>"
!echo $base_address"/file_name.xml"
此外,如果你有一个文件名变量,你可以做类似的事情:
base_address = "<addr>/"
file_name = "file_name.xml"
!echo $base_address$file_name
关于python - 在 Google Colab 的 shell 脚本中连接命令字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61147016/