0
#!/bin/bash

sudo docker-compose -f /home/administrator/compose/docker-compose.yml up --build -d
OUTPUT=$(docker ps | grep 'nginx_custom' | awk '{ print $1 }')

echo $OUTPUT

sudo docker $OUTPUT nginx -s reload

This the the ID that get´s printed correctly in the console.

6e3b3aa3fbc4

This command works fine.

 docker exec 6e3b3aa3fbc4 nginx -s reload

However the variable seems not to get passed to the command here:

sudo docker $OUTPUT nginx -s reload

I am quite unfamiliar with the shell :(. How do I pass the variable to a command that is longer than just echo?

2
  • How do you know it doesn't get passed to the command? What error do you see? Have you tried running set -x before issuing sudo docker ... command to see what's going on? Commented Jun 5, 2020 at 13:30
  • Did you miss out exec? Commented Jun 5, 2020 at 18:21

1 Answer 1

2

add set -x to the script and see what happens: you can probably get rid of grep and incorporate it inside awk

#!/bin/bash
set -x
sudo docker-compose -f /home/administrator/compose/docker-compose.yml up --build -d
OUTPUT=$(docker ps | awk '/ngnix_custom/{ print $1 }')

echo $OUTPUT

sudo docker $OUTPUT nginx -s reload
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.