意外标记'elif'附近的语法错误

Mee*_*ena 2 bash

#!/bin/bash
if [ "$1" = "boot" ]
then
     if [ -f /var/log/boot.log ]
     then
         echo /var/log/boot.log
     elif [ -f /var/log/boot ]
     then
         echo /var/log/boot
     fi
fi
Run Code Online (Sandbox Code Playgroud)

这显示了输出:

: command not foundline 8: GetLogfileName.sh: line 15: syntax error
near unexpected token `elif' 'etLogfileName.sh: line 15: `        
elif [ -f /var/log/boot ]
Run Code Online (Sandbox Code Playgroud)

这里出了什么问题?

gle*_*man 6

出现乱码错误消息表明您的文件在换行符之前有回车符.你在Windows上编辑脚本了吗?使用文本编辑器保存文件而不回车或运行脚本dos2unix(或者可能d2u)