gpt4 book ai didi

linux - 处理在 bash 脚本中调用的 python 文件的输出

转载 作者:太空狗 更新时间:2023-10-29 11:45:39 26 4
gpt4 key购买 nike

这只是我将要享受的 bash 脚本乐趣的开始
由于某种原因,它总是返回 Fail..
而且我不知道为什么,我编写 bash 脚本已经很久了,但这似乎不起作用。

#!/bin/bash

python /var/lib/scripts/Hudson.py result
if test "$result" = "Success"
then
echo "Done"
else
echo "Fail"
fi

python 文件返回SuccessFail

如果有人能为此指出正确的方向,我将不胜感激。

谢谢,罗伯特。
附言。 python 文件将 XLSM 文件转换为已经正常工作的 CSV

最佳答案

如果你指的是 python 的输出,你应该用 $() 来测试它

#!/bin/bash

if test "$(python /var/lib/scripts/Hudson.py result)" = "Success"
then
Run next command
else
Exit the script
fi

而且 [[ ]] 实际上更好

#!/bin/bash

if [[ "$(python /var/lib/scripts/Hudson.py result)" == "Success" ]]
then
Run next command
else
Exit the script
fi

如果您指的是退出代码:

#!/bin/bash

if python /var/lib/scripts/Hudson.py result
then
Run next command
else
Exit the script
fi

关于linux - 处理在 bash 脚本中调用的 python 文件的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18214360/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com