需要帮助解决“意外的文件结束”异常?

时间:2016-07-18 09:04:01

标签: linux bash shell

我正在尝试将2个语句转换为shell脚本

cat all5.log | grep 'Opened\|Closed'> all.log
awk -F ' ' '{print }' all.log | sort | uniq > uniqueFiles.txt

这是monitorFd.sh bash脚本

#!/bin/bash

if [ "" != "" ]; then
    cat  | grep 'Opened\|Closed' > temp.log
    awk -F ' ' '{print }' temp.log | sort | uniq > uniqueFiles.txt

    while IFS='' read -r line || [[ -n "$line" ]]; do
        cmd1=`cat  | grep Opened | grep $line | sort | wc -l`
        cmd2=`cat  | grep Closed | grep $line | sort | wc -l`
        echo 'Opened: '$cmd1', Closed: '$cmd2' '$line
    done < "uniqueFiles.txt"

    rm -f temp.log
else
    echo "No target file provided. (hint: trace dump of file-leak-detector.jar)"  #syntax error: unexpected end of file

在notepad ++中,我将此文件更改为UNIX格式。同时更改了对+ x的权限,但我遇到了异常。

monitorFd.sh: line 16: syntax error: unexpected end of file

enter image description here

这个程序有什么问题?

1 个答案:

答案 0 :(得分:0)

bash中if的语法是if ... else/elif ... fi。所以只需在文件末尾添加fi即可。