I\'m trying to execute a simple if else statement in a Makefile:
check:
if [ -z \"$(APP_NAME)\" ]; then \\
echo \"Empty\" \\
else \\
echo \"Not e
This is shell syntax, not makefiles. You need to familiarize yourself with the rules surrounding using backslashes to enter long commands into a single line of shell.
In your example, after the backslash newline pairs are removed, it looks like this:
if [ -z "$(APP_NAME)" ]; then echo "Empty" else echo "Not empty" fi
Maybe you can now see that the issue is. The shell interprets that as:
if [ -z "$(APP_NAME)" ]; then
followed by a single long command:
echo "Empty" else echo "Not empty" fi
which would echo the content Empty else echo not empty fi
, except that since there's no trailing fi
shell token it's instead a syntax error.
In shell syntax you need to add a semicolon after every individual command, so the shell knows how to split it up:
check:
if [ -z "$(APP_NAME)" ]; then \
echo "Empty"; \
else \
echo "Not empty"; \
fi
Note the semicolons after the echo
commands telling the shell that the command arguments end there.