tags:

views:

2407

answers:

2

I am writing a makefile in bash and I have a target in which I try to find if a file exists and even though I think the syntax is correct, i still gives me an error.

Here is the script that I am trying to run

read: 
        if [ -e testFile] ; then \ 
        cat testFile\ 
        fi

I am using tabs so that is not a problem.

The error is (when I type in: "make read")

if [ -e testFile] ; then \
        cat testFile \
        fi
/bin/sh: Syntax error: end of file unexpected (expecting "fi")
make: *** [read] Error 2
+2  A: 

Try adding a semicolon after 'cat testFile'. For example:

read: if [ -e testFile ] ; then cat testFile ; fi

alternatively:

read: test -r testFile && cat testFile

jwa
the alternate solution works but I have to use the if..then syntax. adding a semicolon does not seem to solve the issue.
Jaelebi
Weird. I tried it the first time with semicolon and it didnt work. th second time I ran it it worked.Thanks
Jaelebi
A: 

I also met this problem.

And the reason is that I added some comments after the "\".

HackNone