小编Avi*_*tor的帖子

shell 脚本中 else 附近的语法错误

我正在尝试下面的代码。因为我试图检查我在下面提到的目录中获得了两个文件,然后我想完全摆脱 while 循环!但是如果我还没有收到文件,那么它应该继续迭代和等待。但是通过使用下面的代码,我在 else 部分遇到了错误。错误是:

syntax error near unexpected token else
Run Code Online (Sandbox Code Playgroud)

我应该怎么做才能修复它?另一个问题是如何在 Visual Studio Code 中格式化我的 shell 脚本,我在 VSC 中找不到它的任何扩展名。

day_of_month=1
export filesdir=/dir1/dir2/dir3
local count=0
numFilesReceived=0
while true; do
        files=$(find $filesdir -name '*.txt.gz' -type f -mmin -1)
        if [ "$day_of_month" == "1" ]; then
            if [ -f "$files" ]; then
                count=$((count + 1))
                break
                if [ "$numFilesReceived" == "$count" ]; then
                    echo "All $count data received!"
                    break 3
                fi
            fi
            else
                echo "No data received yet!" 
            fi
            fi
             else
            rm …
Run Code Online (Sandbox Code Playgroud)

shell bash

0
推荐指数
1
解决办法
145
查看次数

标签 统计

bash ×1

shell ×1