2 added 131 characters in body
source | link

If I understand the question, you want make to configure a shell with some environment such that when make exits, that environment persists.

What the eval command is doing is changing the current shell, but since you are running it from make, it changes only the subshell created by make, which is then destroyed when the make target that invoke `eval is completed.

Every line make is told to run is actually invoked in a shell it creates. Once the command run from make returns, that shell is gone, along with any changes you made in it.

What you need to do is run your eval command in a shell that is used to invoke the docker command, all in the same subshell. That is, every command that a target runs that needs this environment needs to invoke the eval command first. And you have to run the commands in the same shell, instead of a separate subshell for every line.

The easiest way to do this is to string your commands together with ; so that it first sets the environment, and then runs some docker command:

status:
    eval $$$(docker-machine env dev); docker-compose ps

Note the double dollar sign: $ is a special character in make, and you need to escape it as $$ so that the shell sees $.

This is a make-specific version of this answer. So, you can also invoke a script, or us && or anything else you like.

Or, if the docker environment is not configured or changed by make (for example, you don't need to tweak the environment based on make runtime variables), but is predetermined, you run make in a shell that already has the docker environment set. Then each of its subshells will also have the same environment.

There make be some way in the make you are using to collect multiple lines into the same subshell; check your documentation.

If I understand the question, you want make to configure a shell with some environment such that when make exits, that environment persists.

What the eval command is doing is changing the current shell, but since you are running it from make, it changes only the subshell created by make, which is then destroyed when the make target that invoke `eval is completed.

Every line make is told to run is actually invoked in a shell it creates. Once the command run from make returns, that shell is gone, along with any changes you made in it.

What you need to do is run your eval command in a shell that is used to invoke the docker command, all in the same subshell. That is, every command that a target runs that needs this environment needs to invoke the eval command first. And you have to run the commands in the same shell, instead of a separate subshell for every line.

The easiest way to do this is to string your commands together with ; so that it first sets the environment, and then runs some docker command:

status:
    eval $(docker-machine env dev); docker-compose ps

This is a make-specific version of this answer. So, you can also invoke a script, or us && or anything else you like.

Or, if the docker environment is not configured or changed by make (for example, you don't need to tweak the environment based on make runtime variables), but is predetermined, you run make in a shell that already has the docker environment set. Then each of its subshells will also have the same environment.

There make be some way in the make you are using to collect multiple lines into the same subshell; check your documentation.

If I understand the question, you want make to configure a shell with some environment such that when make exits, that environment persists.

What the eval command is doing is changing the current shell, but since you are running it from make, it changes only the subshell created by make, which is then destroyed when the make target that invoke `eval is completed.

Every line make is told to run is actually invoked in a shell it creates. Once the command run from make returns, that shell is gone, along with any changes you made in it.

What you need to do is run your eval command in a shell that is used to invoke the docker command, all in the same subshell. That is, every command that a target runs that needs this environment needs to invoke the eval command first. And you have to run the commands in the same shell, instead of a separate subshell for every line.

The easiest way to do this is to string your commands together with ; so that it first sets the environment, and then runs some docker command:

status:
    eval $$(docker-machine env dev); docker-compose ps

Note the double dollar sign: $ is a special character in make, and you need to escape it as $$ so that the shell sees $.

This is a make-specific version of this answer. So, you can also invoke a script, or us && or anything else you like.

Or, if the docker environment is not configured or changed by make (for example, you don't need to tweak the environment based on make runtime variables), but is predetermined, you run make in a shell that already has the docker environment set. Then each of its subshells will also have the same environment.

There make be some way in the make you are using to collect multiple lines into the same subshell; check your documentation.

1
source | link

If I understand the question, you want make to configure a shell with some environment such that when make exits, that environment persists.

What the eval command is doing is changing the current shell, but since you are running it from make, it changes only the subshell created by make, which is then destroyed when the make target that invoke `eval is completed.

Every line make is told to run is actually invoked in a shell it creates. Once the command run from make returns, that shell is gone, along with any changes you made in it.

What you need to do is run your eval command in a shell that is used to invoke the docker command, all in the same subshell. That is, every command that a target runs that needs this environment needs to invoke the eval command first. And you have to run the commands in the same shell, instead of a separate subshell for every line.

The easiest way to do this is to string your commands together with ; so that it first sets the environment, and then runs some docker command:

status:
    eval $(docker-machine env dev); docker-compose ps

This is a make-specific version of this answer. So, you can also invoke a script, or us && or anything else you like.

Or, if the docker environment is not configured or changed by make (for example, you don't need to tweak the environment based on make runtime variables), but is predetermined, you run make in a shell that already has the docker environment set. Then each of its subshells will also have the same environment.

There make be some way in the make you are using to collect multiple lines into the same subshell; check your documentation.