在bash脚本中转义引号和括号的问题 运行这个
>>> c = []
>>> c.extend((2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> c.extend((2,))
>>> c
[2]
结果是:
a="{\'copa\':\'copa2\'}"
print "$a"
使用in sh参数添加引号arrount aws_instance_tag语句并删除copa值的单引号
{'copa':'copa2'}
结果
sh "ansible-playbook playbooks/environment-provisioning.yml -e env=perf -e num_injectors_zone_a=2 -t performance_services -e aws_instance_tags=${a} "
答案 0 :(得分:0)
不要使用字符串化命令,而是尝试使用数组:
# 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[@]}"