0

I have the code fragment you can see below in my Makefile I'm trying to write

When I run it, it gives me an unexpected end of file error on the first "do"

I've tried to remove the backslashes, remove as many spaces as I can, etc but I still can't seem to get it to work. Responses to most questions like this here involved people either forgetting to include a "done" or having kerning issues. That doesn't seem to be the case in my code

for i in 1 10 25 50 100 1000 10000;\
do\
    for j in 1 10 25 50 100 1000 10000;\
    do\
        ./myprogram --threads=j iterations=i>>myfile.csv;\
    done\
done

It's supposed to execute the test script above and append the answers to myfile.csv

Instead, I'm getting the following error:

/bin/sh: -c: line 7: syntax error: unexpected end of file
make: *** [tests] Error 1

Thanks!

user71611
  • 11
  • 3
  • 1
    Why even adding all the simicolons and backslashes? Should be fine if you remove the backslash from the myprogram line. Backslashes "escape" the next charackter which would be new line, then done is not interpreted correctly and it fails. – C. Jani Aug 03 '19 at 06:06
  • Is `done\(newline)done` evaluated as `donedone`, and not `done;done`? – Walter A Aug 03 '19 at 13:40
  • Wrong reference to shell variables and missing `;` after the first `done`. See [cider](https://stackoverflow.com/users/2326788/cider) response. – Renaud Pacalet Aug 03 '19 at 14:41

1 Answers1

1

This is a possible duplication of: How to write loop in a Makefile?

I could not get your error running your code, but I did notice you did not refer the variables correctly. In order to get the value of variable i, you should write $$i in a Makefile script.

In your case:

Makefile

target:
        for i in 1 10 25 50 100 1000 10000; \
        do \
                for j in 1 10 25 50 100 1000 10000; \
                do \
                        ./myprogram --threads=$$j iterations=$$i>>myfile.csv; \
                done ; \
        done
Community
  • 1
  • 1
Cider
  • 325
  • 1
  • 13