I am observing a weird issue where when I substitute a variable(A) within another variable(B) and print variable B , the console output is messed up.
docker_command="docker ps | grep consul | awk '{print \$1}'"
container_id=$(execute_command_on_host $IP $USER_NAME $USER_PASSWD "$docker_command")
echo "container_id: $container_id"
service_command="docker exec "$container_id" consul catalog services"
echo "service_command: $service_command"
#run script
Output:
container_id: 411d55019dba
consul catalog servicesommand: docker exec 411d55019dba
The last line of the output is messed up and sort of jumbled. But the same script if I run directy using the container_id then it works
container_id="411d55019dba"
service_command="docker exec "$container_id" consul catalog services"
echo "service_command: $service_command"
#run script
Output:
service_command: docker exec 411d55019dba consul catalog services
I feel I am missing out on something very simple. Would appreciate any help