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
An Unexpected end of file error in a Bash script usually occurs when you there is a mismatched structure somewhere in the script. If you forget to close your quotes, or you forget to terminate an if statement, while loop, etc, then you will run into the error when you try to execute your Bash script.
One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.
Try adding a semicolon after cat testFile
. For example:
read:
if [ -e testFile ] ; then cat testFile ; fi
alternatively:
read:
test -r testFile && cat testFile
I ran into the same issue. This should do it:
file:
@if [ -e scripts/python.exe ] ; then \
echo TRUE ; \
fi
Since GNU Make 3.82, you can add .ONESHELL:
to the top of the file to tell make to run all the lines within a target in a single shell.
.ONESHELL:
SHELL := /bin/bash
foobar:
if true
then
echo hello there
fi
See the documentation.
Prepend lines with @
or add the .SILENT:
option beneath .ONESHELL:
to suppress echoing lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With