0

I need to interpret a python program line by line. I am using -c option to python and have makefile like this.

all:   
python -c  
"print 'aa'  
   print 'bb'"

When I run it with make I get

python -c "print 'aa'
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [all] Error 2

when I take out the same python lines and run from bash, it works fine. What could be the problem?

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
username_4567
  • 4,737
  • 12
  • 56
  • 92

3 Answers3

1

Every line of a make rule is executed in a different shell instance. You need to escape the newlines (with \) or put it all on one line.

Also the makefile snippet as given should be giving you an error about unexpected arguments to -c. Your error indicates that your snippet is actually:

all:   
python -c "print 'aa'  
   print 'bb'"

Not that that changes anything.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
1

If your Makefile truly is

all:   
python -c  
"print 'aa'  
   print 'bb'"

I would expect to see more errors. With that makefile, make will first attempt to run python -c, which should generate errors like:Argument expected for the -c option. It will then abort and not even try to run the shell command "print 'aa'. You need line continuations and semi-colons.

all:   
        python -c   \
        "print 'aa';   \
        print 'bb'"

The semi-colon is necessary because make strips all the newlines and passes the string python -c "print 'aa'; print bb'" to the shell (whatever SHELL is set to).

William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

Have a look at this question. I think your problem is that your program is spanning multiple lines, but your makefile isn't interpreting it that way. Adding slashes should clear that up.

Multiline bash commands in makefile

Community
  • 1
  • 1