I would like to execute a script on a host machine (script_on_host.sh
), which then reaches inside a docker container in order to grab some data using a second script (script_in_container.sh
). The data is only available inside the container, and not from the host directly, hence the reason for doing it this way.
I am having trouble passing data between the two scripts. I tried the following:
script_in_container.sh
#!/bin/bash
x=1
y=2
z=6.3
echo $x
echo $y
echo $z
script_on_host.sh
#!/bin/bash
results=$(docker exec mycontainer './script_in_container.sh')
X=$results(1)
Y=$results(2)
Z=$results(3)
But it throws an error. Can someone help me with this? Is there a nice or more standard way to go about passing variables in this way? I feel like I'm maybe doing something a little clumsily here, by using echo to print multiple lines from the container script.
$results(1)
is the way to refer to the first word of$results
? If$results
were an array, it would use[]
as the way to index it, and indexes start at 0.