Gheorghe Frunza
Gheorghe Frunza

Reputation: 21

Issue with escaping quotes and curly brackets in bash script

Issue with Escaping quotes and brackets in bash script Running this

a="{\'copa\':\'copa2\'}"
print "$a"

The result is:

{'copa':'copa2'}

Using a in a sh command adds quotes arrount aws_instance_tag statement and removes the single quotes for copa values

sh "ansible-playbook playbooks/environment-provisioning.yml -e env=perf -e num_injectors_zone_a=2 -t performance_services -e aws_instance_tags=${a} "

Result

ansible-playbook playbooks/environment-provisioning.yml -e env=perf -e
num_injectors_zone_a=2 -t performance_services -e
'aws_instance_tags={copa:copa2}'

Upvotes: 0

Views: 1527

Answers (1)

glenn jackman
glenn jackman

Reputation: 247012

Instead of stringifying the command, try using an array:

# define the array
cmd=(
    ansible-playbook 
    playbooks/environment-provisioning.yml 
    -e env=perf 
    -e num_injectors_zone_a=2 
    -t performance_services 
    -e aws_instance_tags="$a"
)
# then run it
"${cmd[@]}"

Upvotes: 2

Related Questions