# Use of expr in Makefile



## tommyhp2 (Mar 19, 2020)

Hello everyone,

I'm trying to make a patch for an outdated ported.  Unfortunately, I need to do a string comparison in the Makefile like so:

```
STRING1=12
STRING2=34

.if `${EXPR} "${STRING1} < ${STRING2}"`

.endif
```
I've tried all these variations:

```
(${EXPR} "${STRING1} < ${STRING2}")
${EXPR} ${STRING1} < ${STRING2}
$((${EXPR} "${STRING1} < ${STRING2}"))

# This works in the shell
expr "${STRING1} < ${STRING2}"
# Would produce: 12 < 34
```
All forms I've tried I've ended getting malformed condition.  Has anyone used the expr command in the Makefile?

Thanks,
Tommy


----------



## Bobi B. (Mar 19, 2020)

You can use

```
res!= expr 1 + 2
all:
    echo ${res}
```
as well as

```
res!= test "${STRING1}" \< "${STRING2}" && echo 1 || echo 0
all:
    echo ${res}
```
to run a (shell) command in in POSIX makefiles.

Why would you need string comparison?


----------



## tommyhp2 (Mar 19, 2020)

Hi Bobi,

Thanks for the feedback.  I'll try your suggestions.  I was using:

```
.if ${STRING1} < ${STRING2}

.endif
```

And the port works as expected.  But when testing for compatibility with other ports, `poudriere distclean -a`
broke and complained about malformed conditional even though `poudriere bulk ...` works fine.  But after some research, I think it may a bug in poudriere since another experiencing similar error for configuring a port PR 226695


----------

