Getting multiple variables from the output of docker exec command in a bash script?
5
votes
4
answers
545
views
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.
Asked by teeeeee
(305 rep)
Dec 23, 2024, 10:01 PM
Last activity: Dec 24, 2024, 07:15 PM
Last activity: Dec 24, 2024, 07:15 PM