如何将Python变量传递给Bash? [英] How do I pass a Python Variable to Bash?

查看:58
本文介绍了如何将Python变量传递给Bash?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Python变量传递给Bash shell?它应该像这样工作: foo ="./RetVar.py 42"

How would I pass a Python variable to the Bash shell? It should work like this: foo="./RetVar.py 42"

将双引号替换为`s

我尝试打印并sys.exiting结果,但无济于事.我将如何实现我的目标?

I have tried printing and sys.exiting the result, but to no avail. How would I accomplish my goal?

推荐答案

foo="$(scriptthatprintssomething)"

就是这样.打印.或 sys.stdout.write().之类的.如果脚本不可执行,则需要显式指定解释器.

That's it. print. Or sys.stdout.write(). Or the like. If the script isn't executable then you'll need to specify the interpreter explicitly.

foo="$(python scriptthatprintssomething.py)"

这篇关于如何将Python变量传递给Bash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆