在 bash 脚本中运行 python 命令并获取结果

问题描述 投票:0回答:2

我想在 bash 脚本中运行一个返回

true
false
的 python 命令:

#!/usr/bin/env bash

Some stuff...
boolean = $(python -c "bool(...operations...)")

上面的代码只是勾勒出这个想法。我需要布尔值是

false
true
(bash 布尔值),具体取决于
...operations...
的结果。上面的代码不起作用:
boolean
结果是一个空变量。

python bash shell
2个回答
2
投票

bool=$(python -c 'print(bool("abc"))')
按预期工作。

请注意,这将返回

True
False
,而不是
true
false
(即大写)。


0
投票

xonsh shell 对于 bash 和 python 的混合应该很有用

© www.soinside.com 2019 - 2024. All rights reserved.