0

我正在设置一个 shell 脚本,它使用以下命令读取日志文件的最后一行:

tail -1 "/path/to/gdscript.log"

..这很好地呼应了脚本的最后一行。日志的最后一行指示该过程是成功还是失败,因此我尝试按如下方式运行快速回显(这是我失败的地方):

if [ (tail -1 "/path/to/gdscript.log")  == "Process Complete" ]; then
echo "Data Transfer OK"
else
echo "Data Transfer Failed"
exit 1
fi

..但使用上面的脚本我得到:

./gdscript.sh: line 14: syntax error near unexpected token `tail'

知道的人可以告诉我如何格式化上面的 IF 门,以便我可以处理日志文件的最后一行吗?我是 shell 脚本的新手,非常感谢您的帮助。

谢谢,保罗·G

4

2 回答 2

4

要获得您需要的命令的输出$(cmd...)。所以我认为你的意思是:

if [ "$(tail -1 '/path/to/gdscript.log')"  == "Process Complete" ]; then
...
于 2012-09-24T02:24:10.810 回答
0

你应该使用:
if [ $(tail -1 /path/to/gdscript.log) == "Process Complete" ]; then

于 2012-09-24T03:29:41.800 回答