子文件夹和文件生成文件的嵌套循环问题

nested for loop issue for subfolders and files makefile

我有一个逻辑问题,试图为一个包含两个子文件夹和代码文件的 fpöder 做一个嵌套的 for 循环。

    for folder in $(twofolders); do \
        for file in $$folder; do \
            zip -j $$file"_lambda.zip" $(PYTHONPATH)/$$file/*.py; \
            aws s3 cp ./$$file"_lambda.zip" s3://$(S3_BUCKET)/$(SOURCE_CODE_VERSION)/lambda/; \
        done
    done

但是我收到以下错误

/bin/bash: -c: line 5: syntax error: unexpected end of file
make: *** [Makefile:62: build] Error 1

有人知道我做错了什么吗?

您忘记了第一个 done 之后的续行。你绝对应该 double-quote bash 并进行变量扩展:

target: prerequisites
    for folder in $(twofolders); do \
        for file in "$$folder"; do \
            zip -j "$${file}_lambda.zip" "$(PYTHONPATH)/$$file"/*.py; \
            aws s3 cp ./"$${file}_lambda.zip" s3://"$(S3_BUCKET)/$(SOURCE_CODE_VERSION)"/lambda/; \
        done \
    done