Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simplest bash string comparison in makefile is failing [duplicate]

My makefile is as follows:

test:
    if [ "a" == "a" ]; then echo "hooray"; fi

running make test yields the following error:

/bin/sh: 1: [: a: unexpected operator

(Note, if I change the conditional to "a" == "b", the error still refers to "a", so the "problem" is (at least) with the first "a").

I feel like I must be missing something silly, but I cannot get this to work, and can't think of any way to further simplify the problem.

I'm on a raspberry pi (raspbian), running the default/latest everything (apt-get update && apt-get upgrade daily).

like image 392
Phildo Avatar asked Nov 21 '25 06:11

Phildo


1 Answers

Gah. The clue is /bin/sh. apparently make doesn't use bash as its shell under my configuration? very strange...

Anyways, == isn't POSIX sh. Even this cheat sheet: https://www.joedog.org/articles-cheat-sheet/ gets it wrong (thank you Rebecca Cran, who commented as such a year ago...)

To be clear- the solution is to use a single =, as in:

test:
    if [ "a" = "a" ]; then echo "hooray"; fi
like image 145
Phildo Avatar answered Nov 22 '25 21:11

Phildo