Home > Software engineering >  nested for loop issue for subfolders and files makefile
nested for loop issue for subfolders and files makefile

Time:02-01

I have a logical issue, trying to do a nested for loop for a fpöder which holds two subfolders with code files in it.

    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

But I receive the following error

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

Anyone knows what Iam doing wrong?

CodePudding user response:

You forgot a line continuation after the first done. And you should definitely double-quote bash and make variable expansions:

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
  •  Tags:  
  • Related