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

标签 linux bash

这只是我将享受 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/

相关文章:

linux - 如何在bash函数中将数字显示到小数点后两位

c - 带逗号的返回语句

linux - NUMA 机器上的共享库瓶颈

bash - 无法将添加了 PNG 图像的特定提交推送到 github

linux - bash:/bin/tar: 使用 tar 压缩许多文件时参数列表太长

ruby - 使用Ruby通过SSH发送脚本

java - 如何使用 Shell 脚本在日期模式之前换行?

linux - Bash 脚本 - if block 中的 boolean 值?

python - 无法使用 Fabric 和 nohup 真正后台 SSH 隧道

linux - 获取Centos版本的值