Eval in docker machine: terminal vs shell script

I am trying to run a simple shell script to automate changes to the docker environment. The problem is that when I run the following command directly on a Mac terminal, the following is output:

eval $(docker-machine env default)
docker-machine ls
NAME    ACTIVE   DRIVER         STATE     URL                         SWARM   DOCKER    ERRORS
default *        digitalocean   Running   tcp://***.**.***.***:****            v1.12.0   

So basically what you expect, however, when I run the following .sh script:

#!/usr/bin/env bash
eval $(docker-machine env default)

Conclusion:

./run.sh
docker-machine ls
NAME    ACTIVE   DRIVER         STATE     URL                         SWARM   DOCKER    ERRORS
default          digitalocean   Running   tcp://***.**.***.***:****           v1.12.0   

Basically, he does not set it as active, and I cannot access it.

Has anyone encountered this problem before and knows how to solve it? It seems to be really strange, I have everything that works and is automated separately from this facet.

Cheers, Aaron

+4
source share
1 answer

, script

source ./myscript.sh

eval , , . , .

a.sh

#!/bin/bash
eval $(echo 'export a=123')
export b=234

$ ./a.sh
$ echo $a

$ echo $b


$ source a.sh
$ echo $a
123
$ echo $b
234
$
+4

Source: https://habr.com/ru/post/1650019/


All Articles