最近在编写gitlab-cy.yam配置任务时,发现在gitlab中使用for循环会报语法错误
sshpass -p "xx" ssh root@xx.x.xx.xx "for i in {1..6}; do echo $i >> /voc/for_test; done"
但这条命令并没有什么问题,无论我复制在操作的服务器还是gitlab容器里面这条命苦都不会报相应的错误,但就是在gitlab-ci.yam运行时,报语法错误,经过几小时的排错,发现在$前面加上转移符,命令就能正常运行。但具体原因也不是很清楚,有可能gitlab-cy.yam把$后面当作gitlab里的环境变量,但是系统里并没有这个环境变量。
在$前加上\ 正常运行
sshpass -p "xx" ssh root@xx.x.xx.xx "for i in {1..6}; do echo \$i >> /voc/for_test; done"
但后面发现有些语句加上转义符还是继续报错
- sshpass -p "xxx" ssh -o StrictHostKeychecking=no root@x.x.x.x "for i in {1..6}; do sed -i "s/childId:\ waitToConfig/childId:\ 5\$((\${i}-1))/g" /voc/sichuan01-0\$i-5\$((\${i}-1))/prd/pa