N
N
nepster-web2017-10-06 17:45:03
bash
nepster-web, 2017-10-06 17:45:03

How to use ifeq to test the output of a command?

Working with Makefile, I have the command:

docker-compose exec php-bundle /bin/bash -c "getent passwd docker"

It returns data about the docker user in the docker container, the result can be like this, or if the user is not created, then it is empty:
docker:x:1000:1000::/home/docker:/bin/sh
In the Makefile, I need to check for the existence of the user in the container, that is, execute this command, something like this:
ifeq (ПОЛЬЗОВАТЕЛЬ В КОНТЕЙНЕРЕ СУЩЕСТВУЕТ)
  //
endif

That is, it goes something like this:
ifeq ($(docker-compose exec php-bundle /bin/bash -c "getent passwd docker"), )
   echo 1
endif

The command works, but I never hit the condition. Tell me, please, how can this be resolved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nepster-web, 2017-10-09
@nepster-web

Look, it went something like this:

ifeq ($(shell docker-compose exec php-bundle /bin/bash -c "getent passwd docker"),)
  //
else
  echo User "docker" already exists
endif

In general, most likely the problem was the presence of an extra space.

S
Saboteur, 2017-10-06
@saboteur_kiev

And if so

($(docker-compose exec php-bundle /bin/bash -c "if getent passwd docker; then echo 1; fi"), )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question