Home > OS >  How to form a proper if else in make to find user?
How to form a proper if else in make to find user?

Time:04-08

I am very new to make and have wanted to learn more about conditionals.

I want to check the result of whoami in a makefile but keep getting errors

ifeq ($(whoami), "John")
echo "PC"
else 
echo "Server"
endif

Here it gives me an error on the line echo "Server" saying *** missing separator how do I fix it?

CodePudding user response:

You will want something like this:

#!/bin/bash
if [[ $(whoami) == "John" ]]; then
  echo "PC"
else
  echo "Server"
fi

As mentioned by Primitive, bash does not use ifeq and endif.

EDIT

As per chepner's comment, this question could be about Make and not Bash, in that case, this should work:

SHELL = /bin/sh

USER = $(shell whoami)

buildbegin:
ifeq ($(USER), John)
        @echo PC
else
        @echo Server
endif

Can be tested with make -f $MakeFile

  • Related