从makefile逐行解释python程序

从makefile逐行解释python程序,python,bash,makefile,Python,Bash,Makefile,我需要逐行解释python程序。我在python中使用了-c选项,并且有这样的makefile all: python -c "print 'aa' print 'bb'" 当我用make运行它时,我得到了 python -c "print 'aa' /bin/sh: -c: line 0: unexpected EOF while looking for matching `"' /bin/sh: -c: line 1: syntax error: unexpected

我需要逐行解释python程序。我在python中使用了-c选项,并且有这样的makefile

all:   
python -c  
"print 'aa'  
   print 'bb'"
当我用make运行它时,我得到了

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

当我取出相同的python行并从bash运行时,它工作得很好。可能是什么问题?

make规则的每一行都在不同的shell实例中执行。您需要转义换行符(使用
\
)或将其全部放在一行上

另外,给定的makefile代码段应该为您提供一个有关
-c
的意外参数的错误。您的错误表明您的代码段实际上是:

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

这并不能改变任何事情。

看看这个问题。我认为您的问题在于您的程序跨越了多行,但是您的makefile没有这样解释它。添加斜杠应该可以消除这个问题


如果您的Makefile确实是

all:   
python -c  
"print 'aa'  
   print 'bb'"
我希望看到更多的错误。使用该makefile,make将首先尝试运行
python-c
,这将生成错误,如-c选项所需的
参数。然后它将中止,甚至不会尝试运行shell命令“打印'aa'
。您需要行连续体和分号

all:   
        python -c   \
        "print 'aa';   \
        print 'bb'"
分号是必要的,因为make会去掉所有的换行符并传递字符串
python-c“print'aa';将bb'
打印到外壳(无论外壳设置为什么)